网页无法从Phonegap中的远程服务器检索数据(但在Chrome中运行正常)

Cre*_*ede 3 javascript cors cordova

我正在尝试使用Phonegap 3.1创建一个Android应用程序.该应用程序需要从我的远程服务器检索数据,该服务器正在运行Apache,其中Header set Access-Control-Allow-Origin "*"包含应用程序应从中提取数据的URI的指令集.我已经<access subdomains='true' url='*' />设置了Phonegap的config.xml文件.如果我将网页放入与服务器不同的本地Apache目录(不同物理位置的不同域上的不同机器)并从Chrome调用它,但是当我尝试调用它时,下面的代码可以运行并运行"成功"功能通过Phonegap它会引发一个不太有用的错误{"readystste":0,"responseText":"","status":0,"statusText":"error"}.该"readystate":0像它看起来可能是一个访问或跨站点脚本错误只有在PhoneGap的发生,所以我愿意相信这件事情我需要配置我的结束,但我

感谢您的任何帮助,您可以提供.我需要让它运行起来,并且已经在网上搜索了一个星期,试图让它运行起来.

<!DOCTYPE HTML>
<HTML>
<HEAD>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/affirmation.css">
  <script src="js/jquery-1.10.1.min.js"></script>
  <script>

  $.support.cors = true;

  $(document).ready(function(){

      $.ajax({
        type: 'POST',
        url: 'http://www.remote.server/info/API',
        datatype: 'json',
        data: JSON.stringify(
          { method: 'content',
          params: [
            'text passed to function on server' 
          ],
          id: '1' }
        ),
        success: function(response, textstatus, jqxhr) {
        $('#graf1').text(JSON.stringify(response));
        $('#graf3').text(JSON.stringify(textstatus));
        $('#graf6').text(JSON.stringify(jqxhr));
        },
        error: function(jqxhr, textstatus, errorthrown) {
        $('#graf1').text(JSON.stringify(jqxhr));
        $('#graf3').text(JSON.stringify(textstatus));
        $('#graf6').text(JSON.stringify(errorthrown));
        }

      });          
  });

  </script>

</HEAD>
<BODY>
  <DIV ID="header">JSON Server Test</DIV>
  <DIV ID="content">
  <DIV ID="graf1" CLASS="bodytext"></DIV>
  <DIV ID="graf3" CLASS="bodytext"></DIV>
  <DIV ID="graf6" CLASS="bodytext"></DIV>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

MBi*_*lau 7

尝试把<access origin="*" subdomains="true" />里面www/config.xml的文件,按:http://cordova.apache.org/docs/en/3.1.0/guide_appdev_whitelist_index.md.html#Whitelist%20Guide 在你的问题,你有url,而不是origin.

我想到的另一件事是你用模拟器进行测试吗?如果是这样,您使用的是远程服务器的完整URL还是仅使用localhost?因为localhost在模拟器上将映射回模拟器本身而不是您在计算机上运行的服务器.