一般删除网页数据和jquery下使用Ajax删除数据的区别

1. 一般删除网页数据

就是指用户在点击删除的时候,会跳转到DeleteUser.ashx一般处理程序中,并且通过get传参的方式传递一个id的参数,然后在后台处理

<a href='DeleteUser.ashx?id={0}

具体代码如下:

using CZBK.ItcastProject.Model;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;

namespace CZBK.ItcastProject.WebApp
{
    /// <summary>
    /// UserInfoList 的摘要说明
    /// </summary>
    public class UserInfoList : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            BLL.UserInfoService UserInfoService = new BLL.UserInfoService();
           List<UserInfo>list= UserInfoService.GetList();
           StringBuilder sb = new StringBuilder();
           foreach (UserInfo userInfo in list)
           {                                                                                 //点击删除跳转的地址                                                
               sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td><a href='DeleteUser.ashx?id={0}' class='deletes'>删除</a></td><td><a href='ShowDetail.ashx?uid={0}'>详细</a></td><td><a href='ShowEdit.ashx?id={0}'>编辑</a></td></tr>",userInfo.Id,userInfo.UserName,userInfo.UserPass,userInfo.Email,userInfo.RegTime);
           }
            //读取模板文件
           string filePath = context.Request.MapPath("UserInfoList.html");
           string fileCotent = File.ReadAllText(filePath);
           fileCotent = fileCotent.Replace("@tbody",sb.ToString());
           context.Response.Write(fileCotent);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
UserInfoList.ashx

DeleteUser.ashx 相关代码展示如下

using System;
using
System.Collections.Generic; using System.Linq; using System.Web; namespace CZBK.ItcastProject.WebApp { /// <summary> /// DeleteUser 的摘要说明 /// </summary> public class DeleteUser : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; int id; // out id 就是指将值赋值给id if (int.TryParse(context.Request.QueryString["id"], out id)) { BLL.UserInfoService UserInfoService = new BLL.UserInfoService(); //如果删除成功 if (UserInfoService.DeleteUserInfo(id)) { //页面重定向 context.Response.Redirect("UserInfoList.ashx"); } else { context.Response.Redirect("Error.html"); } } else { context.Response.Write("参数错误!!"); } } public bool IsReusable { get { return false; } } } }

2. 通过Ajax删除网页数据

猜你喜欢

转载自www.cnblogs.com/wangjinya/p/10403808.html