JavaScript的ajax通信实例代码 求 50
展开全部
jquery 的ajax:
$.ajax({
url: "Handler.ashx",
data: { type: 'DelNews', id: id },
success: function (result) {
alert("删除成功!");
location.replace(location.href);
}
});
服务端 handler.ashx中的方法, 注意参数type:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace xx网站后台
{
/// <summary>
/// Handler 的摘要说明
/// </summary>
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
var type = context.Request["type"];
switch (type)
{
case "DelNews":
删除新闻(context);
break;
default:
break;
}
}
public void 删除新闻(HttpContext context)
{
string id = context.Request["id"];
id = id.Substring(0, id.LastIndexOf(','));
var t = id.Split(',');
foreach (var item in t)
{
News.删除新闻(item);
}
context.Response.Write("");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
$.ajax({
url: "Handler.ashx",
data: { type: 'DelNews', id: id },
success: function (result) {
alert("删除成功!");
location.replace(location.href);
}
});
服务端 handler.ashx中的方法, 注意参数type:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace xx网站后台
{
/// <summary>
/// Handler 的摘要说明
/// </summary>
public class Handler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
var type = context.Request["type"];
switch (type)
{
case "DelNews":
删除新闻(context);
break;
default:
break;
}
}
public void 删除新闻(HttpContext context)
{
string id = context.Request["id"];
id = id.Substring(0, id.LastIndexOf(','));
var t = id.Split(',');
foreach (var item in t)
{
News.删除新闻(item);
}
context.Response.Write("");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询