This article mainly summarizes the relevant knowledge of XMLHttpRequest, the core content of Ajax, for everyone. It is very detailed and recommended to everyone. If you need it, please refer to it.
Ajax: "Asynchronous JavaScript and XML" (asynchronous JavaScript and XML), a comprehensive technology: using JavaScript object XMLHttpRequest for asynchronous data exchange; JavaScript operating DOM to achieve dynamic effects; using XHTML CSS to express information ;XML and XSLT manipulate data. This article focuses on using the XMLHttpRequest object for asynchronous data exchange with the server.
How to use
XMLHttpRequest five-step usage:
1. Create the object;
2. Register the callback function;
3. Use open Method sets the basic information for interacting with the server;
4. Sets the data to be sent and starts interacting with the server;
5. Implements the callback function.
Since five steps are required every time the XMLHttpRequest object is used, the use of the object can be encapsulated in a js file, and the corresponding functions can be completed by passing some parameters and using its methods. The implementation is as follows:
//Using the encapsulation method, people only provide http requests, URL addresses, data, success and failure callback methods
//1. Define the construction method of the XMLHttpRequest object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
|
Extension issues
1. Browser cache
2. Chinese garbled characters
3. Cross-domain access
For question 1, Problem 3 can be solved by changing the URL address. Problem 1 can be solved by adding a timestamp at the end of the URL address, and problem 3 can be solved through proxy. Just add the corresponding judgment before executing the third step in send():
// Solve the cache conversion: add the timestamp
1 2 3 4 5 6 7 8 9 10 |
|
Question 3 corresponds to the proxy service End implementation:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
|
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Solution to the problem of ajax cross-domain request data cookie loss
Use ajax to change page content and address bar URL without refreshing
##
The above is the detailed content of Ajax core XMLHttpRequest summary. For more information, please follow other related articles on the PHP Chinese website!