2011-11-25 43 views
4

我正在構建RESTful移動應用程序,並且我喜歡找不到資源時的默認行爲。 jQuery Mobile的顯示了這個:jQuery手機:如何調用此(默認)錯誤加載頁面消息?

enter image description here

然而,當我做我的自定義AJAX中的onError(因爲資源沒有找到)我想顯示看中消息(但是,什麼也沒有發生在我的代碼,默認行爲被忽略):

$("#some-place").bind("pageshow", function() { 
    $.ajax({ 
     type: "POST", 
     url: "some-place/places.json", 
     cache: false, 
     dataType: "json", 
     success: onSuccessInitPlaces, 
     error: onErrorInitPlaces 
    }); 
    return false; 
}); 

function onSuccessInitPlaces(data, status) { 
    // do stuff, not important atm 
} 

function onErrorInitPlaces(data, status) { 
    // pseudocode I'd like to invoke for real 
    // should show attached picture 
    invokeFancyErrorLoadingPage(); 
} 

回答

11
//show error message 
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>YOUR MESSAGE</h1></div>") 
    .css({ "display": "block", "opacity": 0.96, "top": $(window).scrollTop() + 100 }) 
    .appendTo($.mobile.pageContainer) 
    .delay(800) 
    .fadeOut(400, function() { 
    $(this).remove(); 
    }); 
+0

完美,謝謝! – Xorty

+0

只有'display:block'對於css是必要的,如果你確定你的div與標準錯誤div具有相同的類。 – alquatoun

相關問題