Home > Web Front-end > Front-end Q&A > What is the interaction model of ajax

What is the interaction model of ajax

青灯夜游
Release: 2022-01-17 18:05:51
Original
2653 people have browsed it

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.

What is the interaction model of ajax

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()
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template