我写的一个例子
//ajax删除
function DelAttachment(ID)
{
if(confirm("确定要删除附件吗?"))
{
var url="DelAttachment.ashx?ID="+ID+"&rd="+Math.random();
CreateXmlHttp();
ajax_process(url,"spFile");
}
}
function ajax_process(url,id)
{
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = ajax_sumbitemployment;
xmlHttp.send(null);
function ajax_sumbitemployment()
{
if (xmlHttp.readyState == 4){
if(xmlHttp.status==200)
{
if(xmlHttp.responseText=="success")
{
alert("删除成功!");
$("spFile").outerHTML= "";
}
else
{
alert("删除失败!");
}
}
}
}
}
//创建Ajax对象
function CreateXmlHttp()
{
try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
catch (e) { try { xmlHttp = new XMLHttpRequest(); }
catch (e) { xmlHttp = false; }}}
}
</script>
</HEAD>
<BODY>
</BODY>
</HTML>
//DelAttachment.ashx文件
using System;
using System.Web;
public class DelAttachment : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
Table Bll = new Table();
string ID = context.Request.QueryString["ID"];
if (!String.IsNullOrEmpty(ID))
{
if (Bll.DelAttachment(int.Parse(ID))>=0)
{
context.Response.Write("success");
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
ASP.NET手写AJAX
最新推荐文章于 2024-07-25 10:06:21 发布