AJAX = Asynchronous JavaScript and XML.
AJAX is a technology for creating fast dynamic web pages.
AJAX allows web pages to be updated asynchronously by exchanging a small amount of data with the server in the background. This means that it is possible to update a portion of the web page without overloading the entire page.
Before implementing ajax, you must create an XMLHttpRequest object. If the browser that creates this object is not supported, you need to create ActiveXObject. The specific method is as follows:
var xmlHttp; function createxmlHttpRequest(){ if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); } }(1) The following uses the xmlHttp created above to implement the simplest ajax get request:
function doGet(url){ // Note that when passing parameter values, it is best to use encodeURI to handle it, in case of garbled code createxmlHttpRequest(); xmlHttp.open("GET",url); xmlHttp.send(null); xmlHttp.onreadystatechange = function(){ if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) { alert('success'); } else { alert('fail'); } } }(2) Use the xmlHttp created above to implement the simplest ajax post request:
function doPost(url,data){ // Note that when passing parameter values, it is best to use encodeURI to handle it, in case of garbled code createxmlHttpRequest(); xmlHttp.open("POST",url); xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp.send(data); xmlHttp.onreadystatechange = function() { if ((xmlHttp.readyState == 4) && (xmlHttp.status == 200)) { alert('success'); }else{ alert('fail'); } } }The above content is the example code for JavaScript implementation ajax introduced to you by the editor. I hope it will be helpful to you. If you have any questions during the use process, please leave me a message. The editor will reply to you in time. Here, I would like to thank everyone for their support for Wulin.com website. I believe we will do better!