2013-09-24 40 views
-1

當一個帖子失敗時,你會調用哪個jQuery AJAX事件?例如,如果該網站會記錄此消息:當POST失敗時,你會調用什麼樣的AJAX事件?

POST http://s-t-h-c.appspot.com/dispatch 500 (Internal Server Error)

其AJAX事件處理程序處理呢?例如,如果請求是成功的,我們可以使用:

$.ajax({ 

success: function() { 
} 

}); 

我已經嘗試過error:ajaxError:,但他們似乎並沒有能夠趕上這個問題。

任何幫助將不勝感激!謝謝!

〜Carpetfizz

+2

爲什麼不閱讀'$ .ajax()'文檔? – undefined

+0

我已經做了,由於某些原因'錯誤'沒有奏效。 – Carpetfizz

回答

1

爲您添加success:同樣有error:在阿賈克斯

爲樣本代碼,我會在這裏發佈一個

$.ajax({ 
    type: 'GET', 
    dataType: 'json', 
    url: url, 
    timeout: 5000, 
    success: function(data, textStatus){ 
     alert('request successful'); 
    }, 
    error: function(xhr, textStatus, errorThrown){ 
     alert('request failed'); 
    } 
    }); 

乾杯!

+0

非常感謝,這工作!我意識到我正在使用'error :()'的錯誤參數 – Carpetfizz

0
$.ajax(

     { 

     type: "GET", 

     cache: false, 

     url: url, 

     dataType: "xml", 

     contentType: "text/html", 

     success: processData, 

     error: errorAlert 

     }); //end of AJax 



//Package the code that handles 

     //error message in case the request 

     //is not successful: 

     function errorAlert(e, jqxhr) 

     { 

     alert("Your request was not successful: " + jqxhr); 

     } 
相關問題