<httpHandlers>
<add verb="POST,GET" path="AjaxPro/*.ashx" type="AjaxPro.AjaxHandlerFactory, AjaxPro" />
</httpHandlers>
第二步:在服务器端的Page_Load中添加
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(命名空间+页面名称));
}
第三步:服务器端的Ajax方法添加
[AjaxPro.AjaxMethod]
public string GetDownloadStatus(string id)
{
return "返回字符串为:"+id;
}
第四步:在客户端调用方法(注意setTimeout函数,2秒后调用该函数,必须是匿名函数,直接调用无效,不延迟时间)
Code
var element;
function updateStatus(obj) {
var id = window.event.srcElement.getAttribute("id");
setTimeout(function() { DoUpdate(id, obj) }, 2000);
}
function DoUpdate(id, obj) {
var span = document.getElementById(id);
element = span.parentNode.parentNode.parentNode.childNodes(3);
命名空间+页面类名+方法名(参数, CallBackServer); }
function CallBackServer(res) {
element.innerHTML = res.value;
}
四步缺一不可,如果出错请检查是否全部写了
比如页面没有定义的错误,可能是命名空间没有写或者没有在Page_load里面注册
时间不延迟没有用匿名函数调用等等。