一般删除网页数据和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; } } } }
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删除网页数据
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构