/*************Ajax Object*************/
var ajax = new Object;
//this method is to create a xmlhttp instance.
ajax.createXmlHttp = function(){
var xmlh;
try {
xmlh = new XMLHttpRequest();//Firefox or other W3C explorer
}
catch (e) {
try {
xmlh = new ActiveXObject("Msxml2.XMLHTTP");//IE
}
catch (e) {
try {
xmlh = new ActiveXObject("Microsoft.XMLHTTP");//IE
}
catch (e) {
xmlh = null;
}
}
}
return xmlh;
}
//send a ajax request (POST)
ajax.doRequest = function(para, url, handler){
xmlHttp = ajax.createXmlHttp();
if (xmlHttp == null)
return false;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");//setting for post
xmlHttp.onreadystatechange = handler;//set the handler of onready event
xmlHttp.send(para);
}
注:JS之优雅写法。
base.$ = function(id){
return document.getElementById(id);
}