Home > Web Front-end > JS Tutorial > body text

js implementation of Ajax example code

小云云
Release: 2018-03-02 13:24:20
Original
1932 people have browsed it

This article mainly shares with you the example code of JS implementation of Ajax, hoping to help everyone.

The core steps to implement Ajax:
1. Define the object;
2. Open the link;
3. Send data;
4. Process the response status;

5. DOM rendering

1. Why do we need to define objects?

The XMLHttpRequest object is the basis of Ajax. Its function is to be used in the background to realize data exchange between the client and the server.

So:

"
var xhr;
if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
}else{
xhr = new ActiveXObject('Micorsoft.XMLHTTP');
                //在IE5和IE6中只有 ActiveXObject('Micorsoft.XMLHTTP') 能够实现数据交互
}
"
"

"
Copy after login

Related recommendations:

JavaScript implementation of Ajax asynchronous request examples detailed explanation

Native JavaScript implements Ajax asynchronous request

jQuery implements Ajax to verify user name uniqueness

The above is the detailed content of js implementation of Ajax example 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!