我有一个Android应用程序,其中包含对我的远程服务器的ajax json调用。我已经使用eclipse,模拟器(Ripple)测试了应用程序,并在本地服务器上的浏览器中测试了ajax脚本。所有测试工作都很完美但是当我将我的应用程序上传到PhoneGap Build并在我的手机上测试apk文件时,它会在ajax调用上返回状态0。我究竟做错了什么?模拟器和apk之间会有区别吗?
Ajax电话:
var formData = $("#form-id").serialize();
$.ajax({
url: "https://mydomain.com/file.php",
data: formData,
type: 'POST',
dataType: 'json',
timeout: 5000,
success: function(data){
if(data['login'] == 'correct' && data['token'] != 'undefined' ){
window.localStorage["token"] = data['tokenMyMen'];
notifyAlert('Login correct', 'Login');
}else{
notifyAlert('Login incorrect', 'Login');
}
},
error: function(x,e){
if(x.status==0){
notifyAlert('You are offline!!\n Please Check Your Network.', 'Error');
}else if(x.status==404){
notifyAlert('Requested URL not found.', 'Error');
}else if(x.status==500){
notifyAlert('Internel Server Error.', 'Error');
}else if(e=='parsererror'){
notifyAlert('Error.\nParsing JSON Request failed. '+x.status, 'Error');
}else if(e=='timeout'){
notifyAlert('Request Time out.');
}else {
notifyAlert('Unknow Error.\n'+x.responseText, 'Error');
}
}});
config.xml有<access origin="https://mydomain.com" />
远程服务器有:
if($this->user->login($username, $password)){
$token = $this->user->getProperty('token');
$createArray = array();
$createArray['login'] = 'correct';
$createArray['token'] = $token;
$record = $createArray;
echo json_encode($record);
}else{
$record = array('login' => 'incorrect');
echo json_encode($record);
}