Reputation: 1325
I am working on phonegap/cordova 1.7.0. and I am sending ajax request to a server. I need to setup a timeout so simulate it I have included a sleep(30) on the server side and my js on the client side i have a time out of 30000.
After testing I concluded that Android was completly ignoring to check the timeout and iOS fails to make the ajax call altogether but does not give any error.
Can someone help me with this? Is it that ajax timeout does not work under phonegap, is there another way to check timeouts with phonegap ? Here is the js code:
$.ajax({
url: url,
data: data,
type: 'GET',
dataType: data_type,
timeout:3000,
error: function(xhr, status, error){
$('body').trigger('network-error') // triggers standard network error
console.log('network-error')
console.log('request came back with the error '+error)
CallbackFail()
},
success: function(data){
// is called from aSuccessCallback in the return
console.log('success')
console.log(data)
}
})
EDIT
I forgot to mention a major point, I am not directly using jquery but rather zepto.
Upvotes: 3
Views: 2155
Reputation: 1325
I went on zepto's github and it seems that ajax timeout has been an issue for quite some time:
https://github.com/madrobby/zepto/issues/search?q=ajax+timeout
There is little said about whether this has or is being tend to or not. If anyone was using the same library as me, it might be a good idea to use jquery directly...
Upvotes: 0
Reputation: 3839
First of all, make it easy on yourself. Install weinre http://people.apache.org/~pmuellr/weinre/, which will help you trace the ajax requests in realtime; so you can see the exact http response from the server(if any). Basically it has the same interface as google developer tools. You would go to "Network" tab to trace your ajax requests.
In general, there are couple of important caveats to consider when making ajax calls:
Make sure that the server, that you are sending your ajax requests to, is whitelisted, otherwise you will not able to send any ajax requests to it. (Here is how to do it: http://docs.phonegap.com/en/1.9.0/guide_whitelist_index.md.html)
if you are sending ajax requests over https, make sure that your server has valid certs; otherwise it will not work unless you manually ignore invalid certs in your phonegap. Different steps are required for iOS/android - I can point you to the right stackoverflow link if this is the case.
In the end, just wanted to let you know that I am sending ajax requests in my phonegap project without any issues. And timeouts are working as expected.
Upvotes: 2