I am developing an application using phonegap and jQuery and I am facing a problem when performing ajax requests on iOS. I do the request , the php on my server receives the information and echo the correct answer. Turns out my app does not 'get' the information until I interact somehow with the screen (scrolling for example) or really wait too long ( over a minute ). This problem evolved, in the beginning happened just after a few requests and now the first ajax already shows it . Another thing I noticed was, when taking out all ( or almost all ) javascript and/or css ( weird ) the problem disappears as if it was something with the phone memory . When doing the request using async : false
, the problem also disappears! It happens on the iPhone 4 . Was tested on Android and PC (Chrome and Mozilla Firefox ) and it worked fine.
The weirdest thing is that when I interact with the screen , the answer appears, it do not wait a second, it is almost instantaneous ... as if the answer was already there, but not showing up for some reason.
Ps: The error alert don`t appears.
jQuery.ajax({
type: 'GET',
url: 'url',
crossDomain: true,
data: {
data: data
},
error: function() {
alert('error');
}
}).done(function(data) {
alert(data);
});
http://api.jquery.com/jQuery.ajax/
if you are wanting a funciton to be triggered on response i would use the complete instead of done.
My guess is you are not cancelling the click action and the page is refreshing
$(".yourSelector").on("click",function (evt) {
evt.preventDefault();
//your ajax call
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.