iPhone Caching Ajax Requests

873 views
Skip to first unread message

petersjay

unread,
Sep 26, 2012, 10:49:57 AM9/26/12
to phon...@googlegroups.com
I recently updated my app from Cordova 1.7.0 to 2.1.0 as well as my xCode to 4.5. The app uses a lot of Ajax requests for getting information from the server. I am using jquery as to make the ajax requests. At the beginning of my onDeviceReady function I have $.ajaxSetup({cache:false}), as well as cache:false in the actual ajax calls. My app seems to still be holding that data. If I uninstall it and reinstall it gets the correct information 1 time and then just repeats that every time. Is there a setting I am missing in either my calls or the xCode setup that would prevent this? (btw the server also has a no-cache header)

Thanks

Phonegappin

unread,
Sep 26, 2012, 2:02:49 PM9/26/12
to phon...@googlegroups.com
http://stackoverflow.com/questions/12506897/is-safari-on-ios-6-caching-ajax-results

I'm surprised that others haven't seen this.  We seem to be imune in my project because I have written
a plugin to do all XHR.

petersjay

unread,
Sep 26, 2012, 2:15:10 PM9/26/12
to phon...@googlegroups.com
Thanks. I found that afterwards and it helped. My solution was adding the following code into my $.ajax({}) request:

beforeSend: function(xhr) { xhr.setRequestHeader("Cache-Control", "no-cache"); xhr.setRequestHeader("pragma", "no-cache"); },

Ravi

unread,
Sep 26, 2012, 2:42:53 PM9/26/12
to phon...@googlegroups.com

We are facing a strange issue. We integrated barcode scanner in the app,
the scanner is able to read both 1D barcodes and QR codes in dev build.

However when the app is approved and we install from app store, the app
can read 1D barcodes. But on QR codes, the scanner simply keeps staring
at it and does not read it.

Anybody has this issue? Is there a more reliable way to test the app so
I know it works in prod too?



Marc

unread,
Sep 27, 2012, 4:02:52 AM9/27/12
to phon...@googlegroups.com
On Wednesday, 26 September 2012 15:49:57 UTC+1, petersjay wrote:
I recently updated my app from Cordova 1.7.0 to 2.1.0 as well as my xCode to 4.5. The app uses a lot of Ajax requests for getting information from the server. I am using jquery as to make the ajax requests. At the beginning of my onDeviceReady function I have $.ajaxSetup({cache:false}), as well as cache:false in the actual ajax calls. My app seems to still be holding that data. If I uninstall it and reinstall it gets the correct information 1 time and then just repeats that every time. Is there a setting I am missing in either my calls or the xCode setup that would prevent this? (btw the server also has a no-cache header)

Thanks

As a rule I append a random query string, e.g. 

var myNumber = Math.floor(Math.random() * 1000000) 

Charlie

unread,
Oct 25, 2012, 3:38:52 PM10/25/12
to phon...@googlegroups.com
So glad I found this, it was driving me crazy.

Cauli Tomaz

unread,
Oct 25, 2012, 4:38:08 PM10/25/12
to phon...@googlegroups.com
Thanks for the info!

With Jquery, I think a simple "cache: false" might work.

$.ajax({
    type: "POST",
    url: "http://www.domain.com/your.php",
    cache: false,
    data: { _variable: variable },
    success: function(data)
    {
       alert('Success: ' + data);
    },
    error: function (request, status, error)
    {
       alert(request.responseText);
    }
});

Am I wrong?
Reply all
Reply to author
Forward
0 new messages