【发布时间】:2012-08-16 21:43:48
【问题描述】:
我正在尝试从具有 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,但效果不佳。花了几个小时,似乎没有得到任何地方......我的模拟器和电脑上的服务器已连接,因为如果我使用浏览器访问 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
【问题讨论】:
-
Phonegap 应用没有跨域问题,你的 logcat 控制台有异常吗?
-
能否尝试转义网址:
encodeURI("http://10.4.40.235/API.public/index.php")