我正在构建RESTful移动应用程序,我喜欢找不到资源时的默认行为。 jQuery Mobile显示了这个:
但是,当我在onError中执行自定义AJAX时(因为找不到资源)我想显示奇特的消息(但是,我的代码中没有任何反应,默认行为被忽略):
$("#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();
}
答案 0 :(得分: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();
});