Method One,
The parameter type is changed from Get to post
Add parameter cache and set to False
Add Time stamp
The code is as follows |
Copy Code |
$.ajax ({ URL: ' Ios/index ', Cache:false, Type: ' Post ', Data: { Timestamp:new Date (). GetTime () params here }, DataType: ' JSON ' ). Done (function (data) { Codes here }); |
Method Two,
JQuery Load Sample code:
The code is as follows |
Copy Code |
$ (document). Ready (function () { $ ("#labels"). Load ("/blog/categories/labels.html"); Inserts the contents of the labels.html in the DOM element with ID #labels when the page is loaded. }); |
When I update labels.html, the Load method in IE7 is still using the old labels.html, even if I press the Refresh key, it doesn't work. Fortunately jquery provides a way to prevent Ajax from using caching, and adding the following statement to the head's JavaScript file can solve the problem.
The code is as follows |
Copy Code |
$.ajaxsetup ({ Cache:false//Turn off AJAX-appropriate caching }); |
In addition, I'll introduce several ways to fix caching. Note: I have not tested the jquery load problem, these methods are for reference only
In short, get-mode transfer data is small, high processing efficiency, low security, will be cached, and post instead.
You need to be aware of using get methods:
1 for Get requests (or any that involve passing parameters to the URL), the passed parameters are processed first by the encodeURIComponent method. Example: var url = "Update.php?username=" +encodeuricomponent ( username) + "&content=" +encodeuricomponent
(content) + "&id=1";
Use POST method to note:
1. Set header Context-type to Application/x-www-form-urlencode ensure that the server knows that there are parameter variables in the entity. Usually use the setRequestHeader ("Context-type", "application/x-www-form-urlencoded;") of the XMLHttpRequest object. Cases:
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
2. The parameter is a name/value one by one corresponding to the key value pairs, each pair of values separated by the & number. like Var name=abc&sex=man&age=18, pay attention to Var name=update.php?
The abc&sex=man&age=18 and the Var name=?abc&sex=man&age=18 are all wrong;
3. Parameters sent in the Send (parameter) method, example: Xmlhttp.send (name); If it is a get way, direct xmlhttp.send (NULL);
4. Server-side request parameters differentiate get and post. If the Get method is $username = $_get["username"]; If it is the POST method, then $username = $_post["username"];