iOS 7 and 412 precondition failed

With every release of iOS there tend to be some gremlins lurking in Safari, iOS 7 was no different.

When first testing the site I’ve been building in iOS 7 I was getting a failure when resubmitting an AJAX POST request, the response was 412 (Precondition Failed).

Eventually I found this issue explained related to a MooTools issue.

“Safari responds to etags properly and adds “If-None-Match” and “If-Modified-Since” headers to another request for the same file. This makes Apache respond with a 412 status (Precondition Failed) as it should do for “post” requests (according to RFC 2616).”

“Unfortunately Safari doesn’t then deal with the 412 as it does with a 304 (Not Modified). It doesn’t grab what it has in the cache and put it in the response, it gives you nothing.”

The date on that blog post is 04/12/2009! There is no sign of this issue in iOS6 so maybe it’s slipped through the iOS cracks and will be patched

The Fix? Switch to GET and Safari will deal with the request correctly.

Filed under: JavaScript