2010-01-14 52 views
1

我調用load方法。有時它所調用的頁面不存在。在螢火蟲我可以看到404狀態被返回。我如何在jQuery中訪問這個狀態,這樣我就可以處理它了?如何在jquery中返回404狀態

$("#section-main-wrapper").load(uri); 

回答

4

傳遞一個callback function

$("#section-main-wrapper").load(uri, null, function(response, status, xhr) { 
    // Check status 
}); 
+0

冷靜,謝謝:) – frosty 2010-01-14 13:22:28

1
$.ajax({ 
    url: uri, 
    cache: false, 
    success: function(html){ 
    $("#section-main-wrapper").replaceWith(html); 
    }, 

    error: function (XMLHttpRequest, textStatus, errorThrown) { 
    // Do something here 
    this; 
    } 
});