小白教程
所有教程
关于
Search
172.70.178.117
172.70.178.117
参数设置
贡献
退出
操作
编辑
移动
保护
信息
历史
删除
查看“Ajax ajaxerror”的源代码
本页内容
上一节:
Ajax_ajaxcomplete
下一节:
Ajax_ajaxsend
因为以下原因,您没有权限编辑本页:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{DISPLAYTITLE:ajaxError()}}[[Category:jquery ref ajax|9]] = jQuery ajaxError() 方法 = [[jquery ref ajax|jQuery AJAX 方法]] 当 AJAX 请求失败时,触发一个警告框: <sample title="" desc="" lang="html" hererun="1"> $(document).ajaxError(function(){ alert("一个错误发生!"); }); </sample> <run name=""> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>小白教程(xiaobai.wang)</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> </run> == 定义和用法 == ajaxError() 方法规定 AJAX 请求失败时运行的函数。 '''注意:'''自 jQuery 版本 1.8 起,该方法只被附加到文档。 == 语法 == <pre> $(document).ajaxError(function(event,xhr,options,exc)) </pre> {| class="table table-striped table-hover" !width="50%"| 参数 !width="50%"| 描述 |- | function(event,xhr,options,exc) | 必需。规定当请求失败时运行的函数。 额外的参数: * event - 包含 event 对象 * xhr - 包含 XMLHttpRequest 对象 * options - 包含 AJAX 请求中使用的选项 * exc - 包含 JavaScript exception |} == 更多实例 == [[try.php?filename=tryjquery_ajax_ajaxerror_options|使用 xhr 和 options 参数]] 如何使用 options 参数来获得一个更有用的错误消息。 [[jquery ref ajax|jQuery AJAX 方法]]
返回至“
Ajax ajaxerror
”。
上一节:
Ajax_ajaxcomplete
下一节:
Ajax_ajaxsend