2011-11-25 50 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

相关问题