phonegap android ajax调用不起作用

时间:2012-08-16 11:24:02

标签: jquery ajax cordova

我试图通过带有phonegap平台和jquery库的eclipse android模拟器向我开发的计算机进行ajax调用。这是我的服务器在我的计算机上运行的场景,模拟器也是如此。当我尝试用这样的ajax调用时:

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

它不起作用。我假设因为跨域ajax请求,但我该怎么做呢。我也试过10.0.2.2 IP,但它也没有用。花了几个小时,似乎没有得到任何地方....我的模拟器和PC上的服务器是连接的,因为如果我使用浏览器去10.4.40.235/API.public/index.php它的工作...

在LogCat中,我收到以下错误:

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

1 个答案:

答案 0 :(得分:0)

经过3个小时的工作后,我得到了解决方案......这对我有用

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