標籤:
在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); } });}
這樣就可以在資料處理過程中,有載入中的效果。
參考:http://www.cnblogs.com/hiflora/p/3816212.html
http://blog.csdn.net/zht666/article/details/8563025
jQuery Mobile 手動顯示ajax載入器