Home  >  Article  >  Web Front-end  >  What are the steps in the ajax interaction process?

What are the steps in the ajax interaction process?

青灯夜游
青灯夜游Original
2022-01-19 17:46:524836browse

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();

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

ajax.open('GET',url,true);

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

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

4. Send a request

ajax.send(null);

5. Accept server response data

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

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!

Statement:
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