jquery mobile 请求数据方法执行时显示加载中提示框


在jquery mobile开发中,经常需要调用ajax方法,异步获取数据,如果异步获取数据方法由于网速等等的原因,会有一个反应时间,如果能在点击按钮后数据处理期间,给一个正在加载的提示,客户体验会更好一些。

如果需要在页面加载时显示加载器,页面加载完成之后关闭加载器,请参考另一篇文章:jquery mobile在页面加载时添加加载中效果 document.ready 和window.onload执行顺序比较

先看两个方法,显示和关闭,方法来自于参考:http://blog.csdn.net/zht666/article/details/8563025

<script>  
//显示加载器  
function showLoader() {  
    //显示加载器.for jQuery Mobile 1.2.0  
    $.mobile.loading('show', {  
        text: '加载中...', //加载器中显示的文字  
        textVisible: true, //是否显示文字  
        theme: 'a',        //加载器主题样式a-e  
        textonly: false,   //是否只显示文字  
        html: ""           //要显示的html内容,如图片等  
    });  
}  
  
//隐藏加载器.for jQuery Mobile 1.2.0  
function hideLoader()  
{  
    //隐藏加载器  
    $.mobile.loading('hide');  
}  
</script>  

然后在ajax中调用:

//获取进度
function InsertStatus(matterID, obj) {
    var a = $(obj).parent().parent().parent();
    $.ajax({
        type: "POST",
        contentType: "application/json",
        url: "/ToDoList/InsertStatus/?matterID=" + matterID,
        beforeSend: function () {         
            showLoader();
        },
        complete:function(){       
            hideLoader();
        },
        success: function (msg) {
            if (msg > 0) {
                $("#popdiv").text("获取进度成功");
            } else {
                $("#popdiv").text("获取进度失败");
            }
            //弹出提示信息
            $("#GettingProgress").attr('data-rel', 'dialog');
            $("#GettingProgress").trigger('create');
            $("#popdiv").popup("open");
            setTimeout(function () { $("#popdiv").popup("close"); }, 2000);
        }
    });

}

这样就可以在数据处理过程中,有加载中的效果。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM