| import ajaxCore from './ajaxCore'; |
| |
| function ajax(opts, callback) { |
| |
| // cache-buster, specifically designed to work around IE's aggressive caching |
| // see http://www.dashbay.com/2011/05/internet-explorer-caches-ajax/ |
| // Also Safari caches POSTs, so we need to cache-bust those too. |
| var ua = (navigator && navigator.userAgent) ? |
| navigator.userAgent.toLowerCase() : ''; |
| |
| var isSafari = ua.indexOf('safari') !== -1 && ua.indexOf('chrome') === -1; |
| var isIE = ua.indexOf('msie') !== -1; |
| |
| var shouldCacheBust = (isSafari && opts.method === 'POST') || |
| (isIE && opts.method === 'GET'); |
| |
| var cache = 'cache' in opts ? opts.cache : true; |
| |
| if (shouldCacheBust || !cache) { |
| var hasArgs = opts.url.indexOf('?') !== -1; |
| opts.url += (hasArgs ? '&' : '?') + '_nonce=' + Date.now(); |
| } |
| |
| return ajaxCore(opts, callback); |
| } |
| |
| export default ajax; |