Is Safari on iOS 6 Caching $.Ajax Results

Prevent iOS 6 from Caching Ajax POST Requests

Read this thread

Is Safari on iOS 6 caching $.ajax results?

You could disable the caching on webserver level and by using timestamps in the URL.

if ios6 safari is caching ajax calls, is it caching passwords? security risk?

Short version: If you're sending usernames and passwords over the wire in plaintext, you've already opened a huge security hole.

Long version: Browsers will cache based on URI, so if you're sending user/pass as GET variables, then yes it will cache and yes it is a security risk. However, even if the browser didn't cache this, you're still doing something wrong. A third party need only look at the HTTP header to see what the user/pass is.

If you are sending this as POST, it is a bit harder to find the username/password. The browser will not cache the request as the URL is always the same. However, it is still possible to read the content of the request and find the user/pass.

To be the most secure, use HTTPS and pass the values via POST. The entire HTTP request is encrypted, including the headers. However, the browser will still cache the URL, so using GET variables is still a bad idea.

Example from the jQuery documentation on using POST with ajax:

$.ajax({
type: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});

Ajax post request in ios Safari 6 not work

i just read this article at ars technica that seem to be related to your problem.
It seems to be an Apple "over optimization" of Safari in iOS6.

iOS 6 Mobile Safari Session Variables not retained when set via AJAX

I have figure out the issue its because in IOS6 Safari cached ajax requests and responses, so instead on sending request to server it uses cached requests. in order to over come this just add timestamp into your Ajax requests, it will work fine. i have placed code that I have used update your code with the help of this. hope will help you.

this is new variable to overcome this issue parameters.timeStamp = new Date().getTime();

    parameters.qString = location.hash;
parameters.timeStamp = new Date().getTime();//this new line for safari issue

application.ajax({
url: application.ajaxUrl + "ajax",
type: "post",
dataType: "json",
data: $.extend({method:parameters.method}, parameters),
success: function( response ){
stop_spinner();
})
});

Thanks

Safari on iOS involving stale $http.get results

Your response doesn't have any cache control headers. According to this answer browsers are free to do whatever they want if there are no cache control headers. In your case Safari on iOS has decided to cache the content even though that isn't what you want.

You could keep using your workaround, or you could add cache control headers in the response to tell Safari not to cache your response.

Note that RFC's might say that responses should not be cached if there are no cache control headers. (I haven't checked). But browsers often have non-standard behavior that you have to work around.

As an aside - early on in my computer networking job I thought that it was OK to not support browsers and webservers that didn't follow the RFCs. I was wrong.



Related Topics



Leave a reply



Submit