2012-09-13 80 views
0

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

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(); 
+0

嗨!你在控制檯上有任何錯誤嗎? – Littm

+0

「我不相信這種類型的Ajax調用是有用的和強大的」......真的嗎?,這是每個和任何JS ajax _wrapper_的核心/引擎**,你會發現。 – cube

回答

0

你試過 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準備邏輯,這個監聽器將等待任何與運行相關的ajax。

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

另外我注意到你提到phonegap,你目前使用的xhr.js他們建議使用AJAX請求?如果不是我建議研究的東西,由於相同的域策略,您的AJAX可能會以無聲和非常快的速度失敗。 xhr.js結束了相同域策略的界限。