zoukankan      html  css  js  c++  java
  • 一般删除网页数据和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删除网页数据

  • 相关阅读:
    MySQL二进制文件(binlog)
    Linux命令 find和mv的结合使用:查找文件,移动到某个目录
    必会的Linux命令
    Linux kill -9 和 kill -15 的区别
    ansible-playbook 修改主机的host解析
    基于mssql 触发器的访问权限设置
    一个简单的启停服务脚本
    Redis protected-mode属性解读
    Nginx内置变量
    haproxy—TCP负载均衡
  • 原文地址:https://www.cnblogs.com/wangjinya/p/10403808.html
Copyright © 2011-2022 走看看