首页 > 代码库 > jquery mobile中显示加载中提示框和关闭提示框

jquery mobile中显示加载中提示框和关闭提示框

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

先看两个方法,显示和关闭,方法来自于参考: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);        }    });}

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