android模拟器和Restful Web服务无法使用PhoneGap

时间:2013-01-30 13:16:24

标签: ajax cordova android-emulator

当我使用以下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);
                    });
                });         
              });

现在,我想使用此代码访问相同的restful 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"/>

该应用仍然无法正常工作。请有人帮帮忙

1 个答案:

答案 0 :(得分:0)

不确定原点线...你试过了吗?

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

甚至

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

相关问题