What are the steps in the ajax interaction process?

青灯夜游
Release: 2022-01-19 17:46:52
Original
4828 people have browsed it

The steps of the ajax interaction process: 1. Create an XMLHttpRequest object; 2. Specify the type of request, URL and whether to process the request asynchronously; 3. Set the content encoding type when sending information to the server; 4. Send the request; 5. Accept server response data; 6. Use JS and DOM to achieve partial refresh.

What are the steps in the ajax interaction process?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

AJAX stands for Asynchronous JavaScript and XML. It is a set of related technologies for displaying data asynchronously. In other words, it sends and retrieves data without reloading the web page.

Steps of ajax interaction process

1. Create XMLHttpRequest object

var ajax = new XMLHttpRequest();
Copy after login

2. Specify the request type, URL and Whether to handle requests asynchronously.

ajax.open('GET',url,true);
Copy after login

3. Set the content encoding type when sending information to the server

ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
Copy after login

4. Send a request

ajax.send(null);
Copy after login

5. Accept server response data

ajax.onreadystatechange = function () {
    if (obj.readyState == 4 && (obj.status == 200 || obj.status == 304)) { 
    }
};
Copy after login

6. Use JavaScript and DOM to achieve partial refresh

Expand knowledge: What are the several request methods of ajax?

Commonly used post, get, delete. Copy, head, link, etc. are not commonly used.

Difference:

(1)Post is safer than get (because the post parameter is in the request body. The get parameter is above the url)

(2)Get transmission speed is faster than post The speed is determined based on the passed parameters. (post passes parameters through the request body, and the background receives through the data stream. The speed is slightly slower. And get can directly obtain the parameters through url)

(3) There is no limit to the theory of post transmission files, and the small theory of get transmission files 7-8k ie4k or so

(4) get to get data post to upload data (there is a lot of uploaded data and the uploaded data is important data. So post is the best choice in terms of security and data level)

[Related tutorial recommendations: AJAX video tutorial]

The above is the detailed content of What are the steps in the ajax interaction process?. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!