How to write native Ajax: first create an XMLHttpRequest object; then write the callback function onreadystatechange; then configure the request information; and finally send the request.
Ajax (abbreviation for Asynchronous JavaScript and XML) is a web development technology that requests data asynchronously, which is very helpful for improving user experience and page performance.
Simply put, Ajax loads background data through asynchronous requests and renders it on the web page without reloading the page. Common application scenarios include form verification to log in or not.
Successful entry, Baidu search drop-down box prompts, express delivery tracking number query, etc.
If you want to have a comprehensive understanding of Ajax, you can go to Js Tutorial to have a comprehensive understanding of it.
Now Ajax has become very convenient after various optimizations. For example, using Jquery only requires one line to use Ajax.
#So what does native Ajax look like?
Let’s take a look.
readystate:
The state of XMLHttpRequest is stored. Changes from 0 to 4.
0: The request is not initialized
1: The server connection has been established
2: The request has been received
3: The request is being processed
4: Request completed and response ready
status:
200: "OK"
404: Page not found
405: Request Incorrect method
500: Server internal error
403: Request forbidden
Ajax has two request methods:
get request method
post request method
The above is the detailed content of How to write native Ajax. For more information, please follow other related articles on the PHP Chinese website!