基础模板
var xmlHttp =null;
if (window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
else
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
if(xmlHttp == null){
alert("Browser does not support Http Request");
return false;
}
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
var msg = xmlHttp.responseText;
}
}
var url = "./IsLogin";
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlHttp.send("kind="+kind);
超级无敌进阶模板
function createXmlHttp() {
var xmlHttp = null;
if (window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
else {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
if (xmlHttp == null) {
alert("Browser does not support Http Request");
return false;
}
return xmlHttp;
}
function ajax(object,url,method,isyb,onData) {
var xmlHttp;
var msg;
xmlHttp = createXmlHttp();
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
msg = xmlHttp.responseText;
onData(msg);
}
}
xmlHttp.open(method, url, isyb);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
var sendvalue="";
var flag = 0 ;
var length = Object.getOwnPropertyNames(object).length;
for(var p in object){
flag=flag+1;
sendvalue+=p+"="+object[p];
if((flag)<length){
sendvalue+="&";
}
}
xmlHttp.send(sendvalue);
}