Ajax android emulator和restful web服务无法使用PhoneGap
当我使用以下ajax代码测试restful web服务时,它正在运行和工作:Ajax android emulator和restful web服务无法使用PhoneGap,ajax,cordova,android-emulator,Ajax,Cordova,Android Emulator,当我使用以下ajax代码测试restful web服务时,它正在运行和工作: $(document).on('pagebeforeshow','#page2', function(){ $('#submit').click(function() { var name = $("#username").val(); var surname = $
$(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"/>
该应用程序似乎仍然无法运行。有人能帮忙吗?不确定原点。。。您是否尝试过:
<access origin="http://10.0.2.2:80080*" subdomains="true"/>
甚至
<access origin="http://10.0.2.2*" subdomains="true"/>
?不确定原点。。。您是否尝试过:
,甚至是
?这个URL在那个远程服务器上真的有效吗?这正是我所缺少的,谢谢你的帮助!这个答案是在几年前发布的——自那以后,Cordova发生了很多变化,包括它们的配置,因此它可能不再适用于新版本