jQuery Mobile 手動顯示ajax載入器

來源:互聯網
上載者:User

標籤:

在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載入器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.