ajaxError(callback)方法在Ajax请求失败时附加要执行的函数。这是一个Ajax事件。
$(document).ajaxError( callback )
下面是此方法-使用的所有参数的说明
callback - 用于该请求的XMLHttpRequest和设置作为参数传递给此函数。如果处理请求时发生异常,则传递第三个参数,即异常对象。
下面是一个简单的示例,一个简单的示例说明了该方法的用法。
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/ajaxerror.html
来源:LearnFk无涯教程网
<html> <head> <title>The jQuery Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { $("#driver").click(function(event){ /* Assume result.text does not exist. */ $('#stage1').load('/jquery/result.text'); }); $(document).ajaxError(function(event, request, settings ){ $("#stage2").html("<h1>Error in loading page.</h1>"); }); }); </script> </head> <body> <p>Click on the button to load result.text file:</p> <div id="stage1" style="background-color:blue;"> STAGE - 1 </div> <div id="stage2" style="background-color:blue;"> STAGE - 2 </div> <input type="button" id="driver" value="Load Data" /> </body> </html>
这将产生以下输出-
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Tony Bai · Go语言第一课 -〔Tony Bai〕