cordova的ajax,Cordova Ajax request pending for ever

问题

I have a cordova app and it worked fine until this morning. I think it has something to do with the new update to cordova 6.4.0.

Whenever I'm sending an AJAX request to my API and it stay in pending more for ever. I've waiting 15 minutes and they still havn't come back. I have the whitelist plugins updated, i added the correct info in the config.xml :

And there are the version of my cordova and plugins

cordova-plugin-compat 1.1.0 "Compat"

cordova-plugin-file 4.3.0 "File"

cordova-plugin-network-information 1.3.0 "Network Information"

cordova-plugin-whitelist 1.3.1 "Whitelist"

cordova-plugin-x-toast 2.5.2 "Toast"

phonegap-plugin-push 1.8.0 "PushPlugin"

Do you have any ideas on how to fix this

Thanks

edit

Here is the code I am using to make Ajax request. I'm returning the Ajax element so I can attach a .done() or a .fail() function to it.

this.get = function($url, $data, $beforeSend) {

/*if($url.indexOf('http') == -1) {

$url = this.URL_API + $url;

}*/

$url = this.URL_API + $url;

if(typeof $data !== 'object') {

this.error('Erreurs de type de donnée.');

} else {

console.log($url);

return $.ajax({

url: $url,

method: 'GET',

data: $data,

beforeSend: function(xhr) {

if(typeof utils.userdata !== "undefined") {

xhr.setRequestHeader('X-API-KEY', utils.userdata.key);

}

xhr.setRequestHeader('Content-Type', 'application/json');

console.log(utils.userdata);

console.log($data);

if($beforeSend !== null && typeof $beforeSend == "function"){

$beforeSend();

}

}

});

}

}

I'm also adding an X-API-KEY header to my request but that shouldn't be the problem.

回答1:

As you said that it was working fine before updating it to new version of cordova

Then you can downgrade it with the below command and check if everything working fine again or not.

$ sudo npm install -g cordova@6.2.0

And if the problem remain same then there is the problem either from your ajax call or you need to check your API via postman and check if it is working fine or not.

来源:https://stackoverflow.com/questions/41255319/cordova-ajax-request-pending-for-ever

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值