【问题标题】:android emulator and restful web service not working with PhoneGapandroid模拟器和restful web服务不适用于PhoneGap
【发布时间】:2013-01-30 13:16:24
【问题描述】:

当我使用以下 ajax 代码对其进行测试时,我正在运行一个安静的 Web 服务并且它正在工作:

$(document).on('pagebeforeshow','#page2',
    function(){
                $('#submit').click(function() 
                {
                    var name = $("#username").val();
                    var surname = $("#usersurname").val();

                    alert(name + " " + surname);

                    $.getJSON("http://localhost:8080/rest/index.php/api/practice/test/name/"+name+"/surname/"+surname + "/format/json",
                    function(data) 
                    { 
                        alert(data.result);
                    });
                });         
              });

现在我想使用此代码访问相同的宁静 Web 服务,但通过 android 模拟器。这是我在模拟器中使用 PhoneGap 的代码:

$(document).on('pagebeforeshow','#page2',
    function(){
                $('#submit').click(function() 
                {
                    var name = $("#username").val();
                    var surname = $("#usersurname").val();

                    alert(name + " " + surname);

                    $.getJSON("http://10.0.2.2:8080/rest/index.php/api/practice/test/name/"+name+"/surname/"+surname + "/format/json",
                    function(data) 
                    { 
                        alert(data.result);
                    });
                });         
              });

我还对 config.xml 文件进行了如下更改:

<access origin="http://10.0.2.2/rest/index.php/api/practice/test" subdomains="true"/>

该应用程序似乎仍然无法运行。请有人帮忙

【问题讨论】:

  • 不确定原产线...您是否尝试过:&lt;access origin="http://10.0.2.2:80080*" subdomains="true"/&gt;,甚至&lt;access origin="http://10.0.2.2*" subdomains="true"/&gt;?该 URL 是否真的在该远程服务器上工作?
  • 这正是我所缺少的,感谢您的帮助!

标签: ajax cordova android-emulator


【解决方案1】:

不确定原产线...你试过了吗:

<access origin="http://10.0.2.2:80080*" subdomains="true"/>

甚至

<access origin="http://10.0.2.2*" subdomains="true"/>

?

【讨论】:

  • 这个答案是几年前发布的 - 从那时起 Cordova 发生了很大变化,包括它们的配置,因此它可能不再与新版本相关
猜你喜欢
  • 1970-01-01
  • 2012-08-29
  • 1970-01-01
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多