From 098656014870aa59d9ffde51c4021a3e21ddfae0 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Thu, 24 Nov 2016 16:33:52 +0800 Subject: webui: Extend jQuery with "getJSONUncached()" This jQuery extension sent the AJAX GET request but force the requested page NOT to be cached by the browser! NOTE: IE will by default cache the GET request even the contents has changed. Credit: https://stackoverflow.com/a/35130770/4856091 --- fg21sim/webui/static/js/main.js | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'fg21sim/webui/static/js/main.js') diff --git a/fg21sim/webui/static/js/main.js b/fg21sim/webui/static/js/main.js index e6e68c4..c725803 100644 --- a/fg21sim/webui/static/js/main.js +++ b/fg21sim/webui/static/js/main.js @@ -107,7 +107,7 @@ var getCookie = function (name) { /** - * jQuery extension for easier AJAX JSON post + * jQuery extension for handy AJAX POST request using JSON * * NOTE: The XSRF token is extracted from the cookie and posted together. * @@ -124,11 +124,32 @@ jQuery.postJSON = function (url, data, callback) { // Credit: https://stackoverflow.com/a/28924601/4856091 headers: {"X-XSRFToken": getCookie("_xsrf")}, data: JSON.stringify(data), - success: function (response) { - if (callback) { - callback(response); - } - } + success: callback + }); +}; + + +/** + * jQuery extension for *uncached* AJAX GET request using JSON + * + * NOTE: + * IE will by default cache the GET request even the contents has changed. + * + * Credit: https://stackoverflow.com/a/35130770/4856091 + * + * @param {String} url - The URL that handles the AJAX requests + * @param {Object} data - Data object sent to the server with the request + * @param {Function} callback - Function to be called when AJAX succeeded + */ +jQuery.getJSONUncached = function (url, data, callback) { + return jQuery.ajax({ + url: url, + type: "GET", + dataType: "json", + data: data, + // Force the requested page NOT to be cached by the browser! + cache: false, + success: callback }); }; -- cgit v1.2.2