/**/
/*
## 作者:夜无眠
## QQ:27262681
此类用法示例
var a=new ajax();
function s(){
a.send("a.php","a="+encodeURIComponent($("a").value),c,"GET");//GET为可选参数,默认值为POST
}
function c(msg){
$("d").innerHTML=msg;
}
发送的值要用encodeURIComponent转义,变成URL专用编码!
*/
function ajax(callback) {//参数为返回执行函数,this.reback为返回值
var http;
var callback;
this.send=function (url,db,func,method){
callback=func;
method=method?method:"POST";
http=null;//清空http实例
if(window.ActiveXObject){
http = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}
http.onreadystatechange=this.f;
if(method=="GET"){
url+="?"+db;
db=null;
}
http.open(method,url,true);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.send(db);
}
this.f=function (){
if(http.readyState == 4){
if(http.status == 200){
var reback = http.responseText;
callback(reback);
http=null;//注销http实例
}
}
}
}
function $(id) {
return document.getElementById(id);
}
function $name(name) {
return document.getElementsByName(name);
}
## 作者:夜无眠
## QQ:27262681
此类用法示例
var a=new ajax();
function s(){
a.send("a.php","a="+encodeURIComponent($("a").value),c,"GET");//GET为可选参数,默认值为POST
}
function c(msg){
$("d").innerHTML=msg;
}
发送的值要用encodeURIComponent转义,变成URL专用编码!
*/
function ajax(callback) {//参数为返回执行函数,this.reback为返回值
var http;
var callback;
this.send=function (url,db,func,method){
callback=func;
method=method?method:"POST";
http=null;//清空http实例
if(window.ActiveXObject){
http = new ActiveXObject("Microsoft.XMLHTTP");
}else if(window.XMLHttpRequest){
http = new XMLHttpRequest();
}
http.onreadystatechange=this.f;
if(method=="GET"){
url+="?"+db;
db=null;
}
http.open(method,url,true);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.send(db);
}
this.f=function (){
if(http.readyState == 4){
if(http.status == 200){
var reback = http.responseText;
callback(reback);
http=null;//注销http实例
}
}
}
}
function $(id) {
return document.getElementById(id);
}
function $name(name) {
return document.getElementsByName(name);
}