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