I was doing testing work today and found a problem that puzzled me. The getJson method ofjquerycan get the returned result when running on firefox, but when tested on ie8, I found that it was not sent. request, so I couldn't get any returned results. After going through many twists and turns, I found the solution in an online article, so I excerpted it and made some modifications.
1 Make the url different for each call
Method: Add one to the parameter random number.
Example 1:
jQuery.getJSON("$!{Root}/a/a/s.ashx",{ID:"123456",Name: "john",random:Math.random()},function(responseText){}
Example 2:
"xxx.aspx?randID="+Math .random
Example 3:
"xxx.aspx?randID="+ escape(new Date())
2 will cache is set to False
$.ajax does notcacheversion:
$.ajax({ type:"GET" url:'test.html' , cache:false, dataType:"html", success:function(msg){ alert(msg); } });
3. Add the following statement at the top of the labels.html file:
4.loadFunctioncan not only call HTML, but also call script, such as labels.php, you can use the header function in the php file :
header("Cache-Control: no-cache, must-revalidate");
?>
5 Use post instead of get method.
You need to use Post method Note:
Set the Context-Type of the header to application/x-www-form-urlencode to ensure that the server knows that there are parameters in the entityVariables. Usually use XmlHttpRequestObjectSetRequestHeader("Context-Type","application/x-www- form-urlencoded;").
Example:xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
Parameters are key-value pairs with one-to-one name/value correspondence. Each pair of values is separated by an ampersand. For example, var name=abc&sex=man&age=18, pay attention to var name=update. The writing methods of php?abc&sex=man&age=18 and var name=?abc&sex=man&age=18 are both wrong;
The parameters are in the Send (parameter) method Send, for example: xmlHttp.send(name); If it is the get method, directly xmlHttp.send(null);Server sideRequest parametersDistinguish between Get and Post. $username = $_GET["username"]; If it is post mode, then $username = $_POST["username"];
6 Add header("Cache- Control: no-cache, must-reva lidate");
7 Add before sending ajax request xmlHttpRequest.setRequestHeader("If-Modified-Since","0");
8 Add before ajax sends the request xmlHttpRequest.setRequestHeader("Cache-Control","no-cache");
The above is the detailed content of Several methods to solve the caching problem of jQuery.getJSON. For more information, please follow other related articles on the PHP Chinese website!