jQuery ajax - ajaxError() 方法
實(shí)例
當(dāng) AJAX 請求失敗時,觸發(fā)提示框:
$("div").ajaxError(function(){ alert("An error occurred!"); });
定義和用法
ajaxError() 方法在 AJAX 請求發(fā)生錯誤時執(zhí)行函數(shù)。它是一個 Ajax 事件。
語法
.ajaxError(function(event,xhr,options,exc))
參數(shù) | 描述 |
---|---|
function(event,xhr,options,exc) |
必需。規(guī)定當(dāng)請求失敗時運(yùn)行的函數(shù)。 額外的參數(shù):
|
詳細(xì)說明
XMLHttpRequest 對象和設(shè)置作為參數(shù)傳遞給回調(diào)函數(shù)。捕捉到的錯誤可作為最后一個參數(shù)傳遞:
function (event, XMLHttpRequest, ajaxOptions, thrownError) { // thrownError 只有當(dāng)異常發(fā)生時才會被傳遞 this; }