Employee List
后台代码如下:
[WebMethod] public void EmployeeList() { string action = Context.Request.QueryString["a"]; if (action.Equals("add")) { addEmployee(Context.Request, Context.Response); } else if (action.Equals("delete")) { deleteEmployee(Context.Request, Context.Response); } } private void deleteEmployee(HttpRequest httpRequest, HttpResponse httpResponse) { string id = httpRequest.QueryString["id"]; StringBuilder xml = new StringBuilder(""); xml.Append(" "); sendResponse(httpResponse, xml.ToString()); } private void addEmployee(HttpRequest httpRequest, HttpResponse httpResponse) { string uniqueID = storeEmployee(); StringBuilder xml = new StringBuilder("1 "); xml.Append(""); sendResponse(httpResponse, xml.ToString()); } private void addEmployee() { } private void sendResponse(HttpResponse httpResponse, string responseText) { httpResponse.ContentType = "text/xml"; httpResponse.Write(responseText); } private string storeEmployee() { string uniqueID = ""; Random r = new Random(); for (int i = 0; i < 8; i++) { uniqueID += r.Next(9); } return uniqueID; } "); xml.Append(uniqueID); xml.Append(" "); xml.Append("1 ");//书中没有这行代码,请注意 xml.Append("
运行效果如下:
点击删除按钮后: