Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax post request in ios Safari 6 not work

after upgrade to iOS6.0 release, ajax login page stopped working. It looks like ajax post request made by jquery $.ajax is cached in safari even after adding random querystring parameter and set Cache-control to "no-cache" (these found on net as solution for cache problem). First login attempt works fine, but after logout at second login request browser don't get any response body from server. only headers.

The same is working in IOS 6 GM and 5 versions and in all desktop browsers.

Any Ideas?

like image 401
Boris Avatar asked Sep 24 '12 12:09

Boris


2 Answers

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.

like image 194
dweeves Avatar answered Sep 24 '22 02:09

dweeves


This topic is also covered in a lot of detail here: Is Safari on iOS 6 caching $.ajax results?

One additional note, however, not covered in the above.

There was a useful comment re WCF that is also applicable to ASP.NET MVC applications re SetCacheability. I recommend that these calls be limited to non-GET requests, to avoid losing the benefit of cache on GETs.

I use a Controller base class that all of my controllers inherit from for a number of reasons, and this served well in that my Initialize override can handle setting my caching headers.

public class SmartController : Controller
{
    ...
    public HttpContextBase Context { get; set; }

    protected override void Initialize(System.Web.Routing.RequestContext requestContext)
    {
        Context = requestContext.HttpContext;

        if (Context.Request.RequestType != "GET")
        {
            Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
        }

        base.Initialize(requestContext);
        ...
    }
...
}
like image 35
Jim Speaker Avatar answered Sep 25 '22 02:09

Jim Speaker