jQuery ajaxError() 方法
实例
当 AJAX 请求失败时触发提醒:
<!DOCTYPE html><html><head><script src="https://libs.baidu.com/jquery/2.1.4/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>
定义与用法
ajaxError() 方法指定当 AJAX 请求失败时要运行的函数。
注意:从 jQuery 1.8 版开始,此方法只应附加到文档。
语法
$(document).ajaxError(function(event,xhr,options,exc))
| 参数 | 描述 |
|---|---|
| function(event,xhr,options,exc) | 必填。指定请求失败时要运行的函数 额外参数:
|
更多实例
如何使用 options 参数获取更有用的错误消息。