phonegap android ajax调用不工作 [英] phonegap android ajax call doesnt work

查看:120
本文介绍了phonegap android ajax调用不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从eclipse android模拟器使用phonegap平台和jquery库调用ajax调用我的开发计算机。这里是我的服务器在我的电脑上运行的情况相同的模拟器。当我尝试调用ajax像这样:

  $。ajax({
type:POST,
url:http://10.4.40.235/API.public/index.php,
成功:function(data)
{
alert(data);
}
});

它不工作。我假设因为跨域ajax请求,但我怎么能这样做。我也试过10.0.2.2 IP,但它did not工作以及。花费几个小时,而且似乎没有得到任何地方....我的模拟器和服务器在PC上是连接,因为如果我用浏览器到10.4.40.235/API.public/index.php它工作...



在LogCat中我得到以下错误:

  WEb控制台:未捕获SyntaxError:Unexpected indetifier at :http://10.0.2.2/API.public/index.php?calback=jQuery[some numbers] 
在此输入代码

$ 3小时的工作后,我得到了解决方案...这是为我工作



pre> $ .get('http://10.0.2.2/API.public/index.php',function(data){
alert(data);
});


Im trying to make ajax call from eclipse android emulator with phonegap platform and jquery library to my developing computer. Here is scenario my server is running on my computer the same for emulator. When I try to call with ajax like this:

$.ajax({
            type : "POST",
            url : "http://10.4.40.235/API.public/index.php",
            success : function(data)
            {
                alert(data);
            }
 });

It doesnt work. I assume because of cross domain ajax request, but how can I do this. I also tried with 10.0.2.2 IP but it didnt work as well. Spent couple of hours and dont seem to get anywhere.... my emulator and server on pc are connected because if I go with browser to 10.4.40.235/API.public/index.php it works...

In LogCat I get following error:

WEb Console: Uncaught SyntaxError: Unexpected indetifier at: http://10.0.2.2/API.public/index.php?calback=jQuery[some numbers]
enter code here

解决方案

after 3 hours of working I got the solution...This is working for me

$.get('http://10.0.2.2/API.public/index.php', function (data) {
    alert(data);
});

这篇关于phonegap android ajax调用不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆