用 jQuery 的話,可以透過 callback 的第二個參數來判斷狀態,或是直接在 callback 內使用 this 來取得 HTTPRequest 的物件。
function (data, textStatus) {
// data could be xmlDoc, jsonObj, html, text, etc...
this; // the options for this ajax request
// textStatus can be one of:
// "timeout"
// "error"
// "notmodified"
// "success"
// "parsererror"
// NOTE: Apparently, only "success" is returned when you make
// an Ajax call in this way. Other errors silently fail.
// See above note about using $.ajax.
}
|