-
-11 16
-
我在用jquery的时候基本上就只用到ajax这个函数,其他的基本上没有用到过,前两天看到ajaxStart(callback)ajaxStop(callback),试着用了下也非常的好用!今天在手册上看到了ajaxError(callback)这个函数,也蛮好用的!提出来分享下,或者大家可以查看参考手册!
AJAX 请求发生错误时执行函数Ajax 事件。XMLHttpRequest 对象和设置作为参数传递给回调函数。捕捉到的错误可作为最后一个参数传递。Attach a function to be executed whenever an AJAX request fails. This is anAjax Event.The XMLHttpRequest and settings used for that request are passed as arguments to the callback. A third argument, an exception object, is passed if an exception occured while processing the request.返回值
jQuery
参数
callback (Function) : 待执行函数
function (event, XMLHttpRequest, ajaxOptions, thrownError) {
// thrownError 只有当异常发生时才会被传递
this; // 监听的 dom 元素
}示例
AJAX 请求失败时显示信息。
jQuery 代码:
$("#msg").ajaxError(function(event,request, settings){
$(this).append("<li>出错页面:" + settings.url + "</li>");
});本文来源于php爱好者:php教程 —http://www.phplover.cn/
原文地址:http://www.phplover.cn/post/jquery-ajaxError(callback).html
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
- 评论(0)
发表评论 TrackBack