jquery ajaxError()方法怎么用?
ajaxError() 方法规定 AJAX 请求失败时运行的函数。
注意:自 jQuery 版本 1.8 起,该方法只被附加到文档。
语法:
$(document).ajaxError(function(event,xhr,options,exc))
参数 | 描述 |
---|---|
function(event,xhr,options,exc) |
必需。规定当请求失败时运行的函数。 额外的参数:
|
示例:(相关课程推荐:jQuery教程)
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $(document).ajaxError(function(){ alert("一个错误发生!"); }); $("button").click(function(){ $("div").load("wrongfile.txt"); }); }); </script> </head> <body> <div><h2>使用 AJAX 修改文本</h2></div> <button>修改内容</button> </body> </html>
效果:
© 著作权归作者所有
举报
发表评论
0/200