我最近尝试为Android构建一个小的Phonegap应用程序。 我设法让一切都在我的电脑上工作,但是ajax不能在我的Android手机上工作。
我的jquery ajax请求:
$.ajax({
async: false,
type: 'POST',
url: target_url,
crossDomain: true,
cache: false,
contentType: "application/json",
dataType: 'jsonp',
jsonpCallback: "loginSuccess",
error: loginError,
});
target_url的位置为:http://username:password@myip/htpassword/login.php 我正在使用http身份验证。 我还启用了jquery cors支持:
$.support.cors = true;
在config.xml中添加我的ip:
<access origin="<myip>" />
我测试过我的应用程序有互联网连接! 我尝试了几种解决方案,但它们都不适合我。 知道为什么我的应用程序无法从我的手机连接到我的xampp服务器? 提前谢谢!
答案 0 :(得分:0)
尝试将身份验证添加到ajax
请求而不是网址:
$.ajax({
async: false,
type: 'POST',
url: 'http://myip/htpassword/login.php',
username: 'username',
password: 'password',
crossDomain: true,
cache: false,
contentType: "application/json",
dataType: 'jsonp',
jsonpCallback: "loginSuccess",
error: loginError,
});