ajax ajaxError() method
Translation results:
Ajax
English [ˈeɪˌdʒæks] American [ˈeˌdʒæks]
n. The full name is "Asynchronous JavaScript and XML" (asynchronous JavaScript and XML); refers to a A web development technology for creating interactive web applications. ;Ajax copper-tin-lead bearing alloy, Agnes explosive
errors
n. Error (plural form of error); fault, mistake
ajax ajaxError() methodsyntax
Function: ajaxError() method executes the function when an error occurs in the AJAX request. It is an Ajax event.
Syntax: .ajaxError(function(event,xhr,options,exc))
Parameters:
Parameters | Description |
function(event,xhr,options,exc) | Required. Specifies a function to run when a request fails. Additional parameters: event - Contains the event object xhr - Contains the XMLHttpRequest object options - Contains the options used in the AJAX request exc - Contains the JavaScript exception. |
Description: The XMLHttpRequest object and settings are passed as parameters to the callback function. The caught error can be passed as the last parameter: function (event, XMLHttpRequest, ajaxOptions, thrownError) {// thrownError will only be passed when an exception occurs this;}
ajax ajaxError() methodexample
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("div").ajaxError(function(){ alert("发生错误!"); }); $("button").click(function(){ $("h2").text("文本已经改变"); }); }); </script> </head> <body> <div id="txt"><h2>通过 AJAX 改变文本</h2></div> <button>改变内容</button> </body> </html>
Click the "Run instance" button to view the online instance