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') 能够实现数据交互 } " "
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!