About how to use get and post in Ajax, about ajaxgetpost
Problems encountered when using get:
1. Problem 1. cache: When the access url is the same each time, the client directly reads the content in the local cache, even if the background data changes, the foreground will not change;
Solution: In? Link a num = [random number Math. random ()] or num = [timestamp new Date (). getTime ()], '1. php? Username = "May" & '+ num (there is no variable name here to avoid conflict with backend parameters)
2. Problem 2. garbled characters. When Chinese or special characters are passed, garbled characters are displayed on the front-end.
Solution: Use the encoding encodeURI ('snail ')
Test results: By using Chrome testing, the two get problems have been solved.
Post problems:
Post mode. Data is transmitted as parameters in send;
Problem: when no request header is set, the background does not process the data directly; the foreground cannot obtain the data returned by the background.
Solution: manually set the Request Header (xhr. setRequestHeader ('content-type', 'application/x-www-form-urlencoded') to declare the Data type sent
[Note] There is no cache problem in post and no encoding problem (because the request header has already been declared)
Test result: through Chrome testing, the result post does not declare the header information, and the problem exists.
The above is all the content about the get and post usage issues in Ajax. I hope you can provide more support ~