由网友(Scar. 疤痕。)分享简介:我建立REST风格的移动应用程序,我喜欢默认的行为时,未找到资源。 jQuery Mobile的说明这一点:不过,当我做我的自定义阿贾克斯的onError(因为未找到资源)我想显示看中消息(但是,什么都不会发生在我的code,默认行为是忽略不计):$(#有的就地)。绑定(pageshow,函数(){$阿贾克斯({键入:...
我建立REST风格的移动应用程序,我喜欢默认的行为时,未找到资源。 jQuery Mobile的说明这一点:
不过,当我做我的自定义阿贾克斯的onError(因为未找到资源)我想显示看中消息(但是,什么都不会发生在我的code,默认行为是忽略不计):
$(#有的就地)。绑定(pageshow,函数(){
$阿贾克斯({
键入:POST,
网址:有的就地/ places.json
缓存:假的,
数据类型:JSON,
成功:onSuccessInitPlaces,
错误:onErrorInitPlaces
});
返回false;
});
功能onSuccessInitPlaces(数据,状态){
//做的东西,而不是重要的ATM
}
功能onErrorInitPlaces(数据,状态){
//伪code,我想调用真正的
//应该显示附加的图片
invokeFancyErrorLoadingPage();
}
解决方案
//显示错误信息
$(< DIV CLASS ='用户界面加载程序的用户界面,覆盖阴影UI体-E界面角,所有的'>< H1>您的消息< / H1>< / DIV>中)
的.css({展示:块,不透明:0.96,顶:$(窗口).scrollTop()+ 100})
.appendTo($ .mobile.pageContainer)
.delay(800)
.fadeOut(400,函数(){
$(本)上卸下摆臂();
});
I am building RESTful mobile app and I like the default behaviour when resource is not found. jQuery Mobile shows this:
However, when I do my custom AJAX in onError (because resource is not found) I'd like to show fancy message (however, nothing happens in my code, default behavior is ignored):
$("#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();
}
解决方案
//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();
});
相关推荐
最新文章