【发布时间】:2016-01-29 01:03:16
【问题描述】:
我正在做科尔多瓦安卓应用。在这个我想要由 REST api 验证的用户登录功能。但在移动设备中,它给出了 ajax 错误代码 '0' 和 throwedError 空白。我已将我的设备与桌面系统连接以测试应用程序。
在桌面浏览器中运行正常。 我使用了下面的代码,
apiurl = "http://xxx.xxx.xxx.xxx/restapi/";
$.ajax({
url: apiurl+'user-signin/login',
type: 'POST',
dataType :'json'
crossDomain: true,
beforeSend:function(){ $.mobile.loading( 'show' ); },
complete: function() { $.mobile.loading( 'hide' ) },
success: function (res) {
alert(res.status);
if(res.status == "success") {
goInsert(res.result.user_id, res.result.user_name, res.result.user_password);
window.location="dashboard.html";
} else if(res.status == "failed") {
alert(res.msg);
//alert(message[res.msg]);
}
},
error: function(xhr, textStatus, thrownError) {
alert(xhr.status+":"+textStatus+":"+thrownError);
navigator.app.exitApp();
},
data: new FormData($('#loginfrm')[0]),
cache: false,
contentType: false,
processData: false
});
我已经在我的 rest api 中添加了“header("Access-Control-Allow-Origin: *");”。
我也使用了数据类型“jsonp”,但它也不适合我。
有人可以帮我吗?
【问题讨论】:
标签: android jquery json ajax cordova