簡體   English   中英

jQuery Mobile Ajax加載程序圖像

[英]Jquery mobile ajax loader image

我在用phonegap和jQuery構建的移動應用程序中使用此代碼,我想顯示服務器中的圖片,但無法集成showPageLoadingMsg函數,而且我不相信這種Ajax調用showPageLoadingMsg用又強大。 所以我真的想知道我應該使用哪種類型的Ajax調用以及如何在我的Android手機應用程序中使用showPageLoadingMsg()函數。

server = "http://monserveur.com/upload.php";
var wid = $(window).width();
    if (server) {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState == 4){
        alert('ready');

                if (xmlhttp.status == 200  ) {
        alert('200');
                    document.getElementById('ousa').innerHTML = xmlhttp.responseText;
                }
                else {
                    document.getElementById('ousa').innerHTML = "Error retrieving pictures from server.";
                }
            }
        };
        xmlhttp.open("GET", server+"?wid="+wid, true);
        xmlhttp.send();

您是否嘗試過http://api.jquery.com/ajaxStart/

http://api.jquery.com/ajaxStop/

並將它們與此處找到的邏輯相結合

http://www.w3schools.com/jquery/ajax_ajaxstart.asp

$("div").ajaxStart(function(){
  $(this).html("<img src='demo_wait.gif' />");
})ajaxStop(function(){
   $(this).empty();
});

如果將其添加到自執行函數或腳本的dom ready邏輯中,這基本上將添加一個偵聽器,此偵聽器將等待與運行相關的任何ajax。

$.post()
$.get()
$.ajax()
$.getJSON()
$.postJSON()
//any I missed?

我還注意到您提到了phonegap,您當前是否在使用他們建議與AJAX請求一起使用的xhr.js? 如果不建議這樣做,由於相同的域策略,您的AJAX可能會很快安靜地失敗。 xhr.js超出了同一域策略的范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM