Is this the Correct place of using this statement in Jquery
This is the statement which I am referering the below code $.ajaxSetup ({ cache: false});
I have a PHP script which produces JSON. I am consuming this json using:
$.getJSON ("GetDetails.php?id=123",
$("#formname").serialize(),
function(data){
**$.ajaxSetup ({ cache: false开发者_如何学编程});**
//I do all processing with the "data"
});
I have seen various questions for caching in the stack overflow I know this also removes the caching
- $.ajaxSetup ({ cache: false});
- By appending Time
Are there any methods to overcome the Cache. When I use this, it is still caching. I have used the same statement in $.documnet.ready()
, but no use.
That $.ajaxSetup()
call goes before your usage of AJAX methods you want to be affected by it (you just need to run it once, not before every call), like this:
$.ajaxSetup ({ cache: false});
$.getJSON ("GetDetails.php?id=123", $("#formname").serialize(), function(data){
//I do all processing with the "data"
});
Instead, you can use:
$.ajax({
url: "GetDetails.php?id=123",
dataType: 'json',
data: $("#formname").serialize(),
cache: false,
success: function(data){
//I do all processing with the "data"
});
});
This will disable cache for that particular query, so you can use the normal, cache-enabled version of the .ajax
call for other queries. If you want to disable cache throughout your application, you can use Nick's solution.
It's slightly unclear what you're getting at. If you want to prevent the JSON data from being cached by the browser, you should have the PHP script specify that in its headers.
See http://articles.sitepoint.com/article/php-anthology-2-5-caching
精彩评论