Home  >  Article  >  Web Front-end  >  How to implement Ajax GET POST request using native JS

How to implement Ajax GET POST request using native JS

一个新手
一个新手Original
2017-09-27 13:15:092967browse


Defects of traditional methods

Traditional web interaction is that the user triggers an http request to the server, and then after the server receives it, it responds to the user and returns A new page, whenever the server processes a request submitted by the client, the client can only wait idle, and even if it is only a small interaction and only needs to get a simple piece of data from the server, a complete page must be returned. HTML page, and the user has to waste time and bandwidth to re-read the entire page every time. This approach wastes a lot of bandwidth. Since each application interaction requires sending a request to the server, the application's response time depends on the server's response time. This results in a user interface that is much less responsive than native apps.

The emergence of Ajax

The emergence of ajax just solves the shortcomings of traditional methods. AJAX is a technology for creating fast, dynamic web pages. AJAX enables web pages to update asynchronously by exchanging small amounts of data with the server in the background. This means that parts of a web page can be updated without reloading the entire page.

Get request


    
        
        
    

用户名:
密码:

Post request

How to implement Ajax GET POST request using native JS

new_file.php

Note:
ajax request is Asynchronous request, so the third parameter of open should be set to true, but I tried to set it to false during the get request, that is, set it to a synchronous request, and still no error will be reported, but it is still recommended to set it to true: make an asynchronous request.

The above is the detailed content of How to implement Ajax GET POST request using native JS. 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