I am using getJSON
to fetch the results from server side but facing browser cache problems. I want the cache to be false. I tried using this just before my getJSON
call.
$.ajaxSetup({ cache: false })
But I am not getting the expected results. It still shows the old results.
I also identified some other solutions such as using .ajax
but I really don't want to use that.
getJSON(). By adding a unique value to the query string of the request, the request will always be unique and not be cached by the browser - you will always get the latest data. where the number at the end is the timestamp for the moment that the code is called and will therefore always be unique.
getJSON() is equal to $. ajax() with dataType set to "json", which means that if something different than JSON is returned, you end up with a parse error. So you were mostly right about the two being pretty much the same :).
jQuery getJSON() Method The getJSON() method is used to get JSON data using an AJAX HTTP GET request.
It is a callback function that executes on the successful server request. It also has three parameters that are data, status, and xhr in which data contains the data returned from the server, status represents the request status like "success", "error", etc., and the xhr contains the XMLHttpRequest object.
Your code just needs a trigger for it to be enabled.
This will allow you to disable cache in all future ajax
$(document).ready(function() { $.ajaxSetup({ cache: false }); });
Hope it helps :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With