简体   繁体   中英

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?

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.

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);
        ...
    }
...
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM