jQuery AJAX producing 304 responses when it shouldn't

前端 未结 3 1249
粉色の甜心
粉色の甜心 2020-12-14 06:53

This really has me scratching my head. Namely because it only happens in IE, not Firefox, and I was under the impression that jQuery was effectively browser neutral. I\'ve b

3条回答
  •  温柔的废话
    2020-12-14 07:41

    1. Always use POST for calls to methods that modify state, not GET. This should be enough in this instance to prevent IE caching the request.
    2. IE aggressively caches ajax requests (see http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/ and https://blog.httpwatch.com/2009/08/07/ajax-caching-two-important-facts/). To prevent this, you can:
      1. Add a cache busting parameter ($.ajaxSetup({ cache: false }); does this automatically.
      2. Always use POST requests (probably not appropriate in most cases).
      3. Turn on cache headers for AJAX requests server side. The first link demonstrates how to do this using in groovy. Similar methods should apply to any framework.

提交回复
热议问题