Code
//显示消息
function showMsg(div, responseText)
{
document.getElementById(div).innerHTML = responseText;
}
//生成post的query
function generate_post_query(f)
{
var q = '';
for (var i = 0; i < f.elements.length; i++)
{
if (i != 0); q += '&';
q += f.elements[i].name + '=' + f.elements[i].value;
}
return q;
}
//AJAX类
function Ajax()
{
this.xmlhttp = createXmlHttp();
function createXmlHttp()
{
if (window.XMLHttpRequest)
{
// 非IE
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// IE
req = new ActiveXObject("Microsoft.XMLHTTP");
}
return req;
}
Ajax.prototype.ajaxGet = function(url)
{
var responseText = '';
this.xmlhttp.onreadystatechange = function()
{
//this指向触发事件的对象(即xmlhttp)
if (this.readyState == 4)
{
if (this.status == 200)
{
//alert(this_obj.xmlhttp.getAllResponseHeaders());
responseText = this.responseText;
}
else
{
alert('There was a problem with the request. (' + this.status + ')');
}
}
}
this.xmlhttp.open("GET", url, true);
this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.xmlhttp.send(null);
return responseText;
}
Ajax.prototype.ajaxPost = function(url, query)
{
var responseText = '';
this.xmlhttp.onreadystatechange = function()
{
//this指向触发事件的对象(即xmlhttp)
if (this.readyState == 4)
{
if (this.status == 200)
{
responseText = this.responseText;
} else
{
alert('There was a problem with the request. (' + this.status + ')');
}
}
}
this.xmlhttp.open('POST', url);
this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.xmlhttp.send(query);
return responseText;
}
}
//显示消息
function showMsg(div, responseText)
{
document.getElementById(div).innerHTML = responseText;
}
//生成post的query
function generate_post_query(f)
{
var q = '';
for (var i = 0; i < f.elements.length; i++)
{
if (i != 0); q += '&';
q += f.elements[i].name + '=' + f.elements[i].value;
}
return q;
}
//AJAX类
function Ajax()
{
this.xmlhttp = createXmlHttp();
function createXmlHttp()
{
if (window.XMLHttpRequest)
{
// 非IE
req = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// IE
req = new ActiveXObject("Microsoft.XMLHTTP");
}
return req;
}
Ajax.prototype.ajaxGet = function(url)
{
var responseText = '';
this.xmlhttp.onreadystatechange = function()
{
//this指向触发事件的对象(即xmlhttp)
if (this.readyState == 4)
{
if (this.status == 200)
{
//alert(this_obj.xmlhttp.getAllResponseHeaders());
responseText = this.responseText;
}
else
{
alert('There was a problem with the request. (' + this.status + ')');
}
}
}
this.xmlhttp.open("GET", url, true);
this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.xmlhttp.send(null);
return responseText;
}
Ajax.prototype.ajaxPost = function(url, query)
{
var responseText = '';
this.xmlhttp.onreadystatechange = function()
{
//this指向触发事件的对象(即xmlhttp)
if (this.readyState == 4)
{
if (this.status == 200)
{
responseText = this.responseText;
} else
{
alert('There was a problem with the request. (' + this.status + ')');
}
}
}
this.xmlhttp.open('POST', url);
this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
this.xmlhttp.send(query);
return responseText;
}
}