The interaction model of ajax is: 1. The user issues an asynchronous request; 2. Use onReadyStateChange to monitor; 3. Create a request, use the open method to specify whether it is get or post, whether it is asynchronous, and the url address; 4. Send the request; 5. Accept the results and analyze them; 6. Implement refresh.
The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.
The full name of Ajax: Asychronous javascript and xml, is a web development technology for creating interactive web applications.
ajax interaction model
1. The user issues an asynchronous request
2. Use onReadyStateChange to monitor
3. Create a request, Use open method to specify whether it is get or post, whether it is asynchronous, url address
4. Send request, send method
5. Accept the result and analyze
6. Implement refresh
The difference between synchronous and asynchronous:
Synchronous: the script will stay and wait for the server to send a reply before continuing
Asynchronous: the script allows the page to continue its process and processing Possible replies
var xhr = new XMLHttpRequest(); xhr.open('请求方式GET或者POST或者其他', 请求地址url, 是否开启异步async); xhr.onreadystatechange = function() { // readyState == 4说明请求已完成 if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); } } if (method == 'POST') { //给指定的HTTP请求头赋值 xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } xhr.send()
[Related tutorial recommendations: AJAX video tutorial]
The above is the detailed content of What is the interaction model of ajax. For more information, please follow other related articles on the PHP Chinese website!