Home > Web Front-end > JS Tutorial > JS implements AJAX partial refresh (with code)

JS implements AJAX partial refresh (with code)

php中世界最好的语言
Release: 2018-04-02 14:38:04
Original
2086 people have browsed it

This time I will bring you JS to implement AJAX partial refresh (with code). What are the precautions for JS to implement AJAX partial refresh? . The following is a practical case, let's take a look.

AJAX stands for "Asynchronous Javascript And XML" (Asynchronous JavaScript and XML), which refers to a web development technology for creating interactive web applications.

AJAX = Asynchronous JavaScript and XML (a subset of Standard Universal Markup Language).

AJAX is a technology for creating fast, dynamic web pages.

The following is an introduction to the JS implementation of the AJAX partial refresh function. The specific content is as follows:

By exchanging a small amount of data with the server in the background, AJAX can enable asynchronous updates of web pages. This means that parts of a web page can be updated without reloading the entire page.

// 创建XMLHttpRequest对象
 var xhr=new XMLHttpRequest();
  
 // 请求行
 xhr.open('post','03-ajaxPost.php');
 //请求头
 xhr.setRequestHeader('Content-Type',' application/x-www-form-urlencoded');
 //请求主体 post send 设置数据
 xhr.send('name='+txt);
  
 //监听服务器的响应
 xhr.onreadystatechange=function(){
 if(xhr.readyState==4&&xhr.status==200){ //这里表示接受服务器的响应成功的时候
 var r=xhr.responseText;
 document.querySelector('.info').innerHTML=r;
 }
 }
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!

Recommended reading:

How Ajax realizes city secondary linkage

Two methods for Ajax optimization page refresh

The above is the detailed content of JS implements AJAX partial refresh (with code). 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