The examples in this article describe Ajax usage in JavaScript. Share to everyone for your reference. The specific analysis is as follows:
To obtain XMLHttpRequest objects in a compatible way:
var xhr = null;
if (window. XMLHttpRequest) {//non ie browser
xhr = window. XMLHttpRequest;
} else if (window. ActiveXObject) {//ie browser
try{ //high version, supported by msxml3.dll+
XHR = new ActiveXObject ("Msxml2.xmlhttp");
} catch (e) {
try{ //Low version, msxml2.6 the following version uses
XHR = new ActiveXObject ("Microsoft.XMLHTTP");
catch (e) {
alert ("IE browser cannot create ActiveXObject Object!") ");
}
}
}
Ajax processing functions:
Xhr.open ("POST", url,true);
Xhr.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Xhr.onreadystatechange=statechangehandler;
Xhr.send (); var name= "CLF"; Xhr.send (name);
function Statechangehandler () {
if (xhr.readystate==4&&xhr.status==200) {
var obj = document.getElementById ("Targetdiv");
obj.innerhtml = Xhr.responsetext;
}
I hope this article will help you with your JavaScript programming.