代码 复制 - 运行
$(document).on("pageshow","#mypage",function(){
///滑动到底部事件
$(document).unbind("scroll");
$(document).bind("scroll", function(event){
//if( $(document).scrollTop() >= $(document).height()-$(window).height() -50 ){
if( $(document).scrollTop() >= $(document).height()-$(window).height() ){
//do your work
GetAjaxData();
}
});
});
$(document).on("pagehide","#mypage",function(){
$(document).unbind("scroll");
});
function GetAjaxData(){
/////Params.....
$.ajax({
timeout: settimeout,//请求超时时间(毫秒)
async: true,//异步
dataType: "json",//返回json格式的数据
beforeSend: function () {
showLoader();
},
complete: function () {
hideLoader();
},
url: "接口地址?param1=p1&m2=p2",
success: function (data) {
alert("返回数据:"+data);
},
error: function(XMLHttpRequest, textStatus, errorThrown){
alert("异常信息:"+textStatus);
this; //调用本次ajax请求时传递的options参数
}
});
}
function showLoader() {
//显示加载器.for jQuery Mobile 1.2.0 以上
$.mobile.loading('show', {
text: '数据加载中,请稍候', //加载器中显示的文字
textVisible: true, //是否显示文字
theme: 'a', //加载器主题样式a-e
textonly: false, //是否只显示文字
html: "" //要显示的html内容,如图片等,默认使用Theme里的ajaxLoad图片
});
}
function hideLoader()
{
//隐藏加载器
$.mobile.loading('hide');
}