jQuery mobile:如何调用此(默认)错误加载页面消息?

时间:2011-11-25 09:43:06

标签: javascript jquery ajax jquery-mobile

我正在构建RESTful移动应用程序,我喜欢找不到资源时的默认行为。 jQuery Mobile显示了这个:

enter image description here

但是,当我在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();
}

1 个答案:

答案 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();
  });