function JXMLHttp() {
}
JXMLHttp.prototype.instance = null;
JXMLHttp.prototype.context = null;
JXMLHttp.prototype.newInstance = function() { //创建XMLHTTP对象
if(this.instance == null) {
try {
return new ActiveXObject("Msxml2.XMLHTTP");
}catch{
try
{
return new ActiveXObject("Microsoft.XMLHTTP");
}catch{
}
}
}
return null;
}
return this.instance;
}
JXMLHttp.prototype.stop = function() { //停止XMLHTTP运行
if(this.instance != null) {
this.instance.abort();
}
}
JXMLHttp.prototype.request = function(url, data, callback, context) {
this.instance = this.newInstance();
if(this.instance != null) {
var async = typeof(callback) == "function";
if(async) {
this.instance.onreadystatechange = function() {
if(this.instance.readyState == 4) {
callback( this.response());
}
}
}
this.instance.open('POST', url, async);
this.instance.send(data);
if(!async) {
return this.response();
}
}
}
JXMLHttp.prototype.anylseResult = function() { // 分析并返回服务器传给客户端数据
if( (this.instance.responseXML != null) && !(this.instance.responseXML.xml.toString().isNullOrEmpty()) )
return this.instance.responseXML;
var returnVal = null;
eval("returnVal=" + this.instance.responseText + ";" );
return returnVal;
}
JXMLHttp.prototype.response = function() { //
if(this.instance != null) {
var error = "";
var retValue = "";
if(this.instance.status == 200) {
try
{
return this.anylseResult();
}catch
{
}
}
}
return "";
}