2012-09-13 76 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结束了相同域策略的界限。