window.blqw = window.blqw || {};
blqw.Ajax = blqw.Ajax || {};
blqw.Ajax.GetRequest = function () {
if (window.ActiveXObject) {
try {
return new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
}
}
blqw.Ajax.Throw = function(e){{
function AjaxError(message,stack,type){{
this.name = 'AjaxError';
this.type = type;
this.message = message;
this.stack = stack;
this.innerError = null;
this.toString = function () {{
return 'ajaxerr:' + this.message;
}};
}};
var err = new AjaxError(e.message,e.stack,e.type);
var e1 = err;
while(e.innerError){{
e = e.innerError;
e1.innerError = new AjaxError(e.message,e.stack,e.type);
e1 = e1.innerError;
}}
return err;
}}
blqw.Ajax.Exec = function (method, args) {
var getStr = function (obj) {
if (obj == null) return '';
var type = typeof (obj);
switch (type) {
case 'number':
case 'boolean':
return obj.toString();
case 'string':
return encodeURIComponent(obj.replace('\0', '\0\0'));
case 'undefined':
return 'undefined';
case 'function':
try {
return arguments.callee(obj());
} catch (e) {
return 'null';
}
case 'object':
type = Object.prototype.toString.apply(obj);
switch (type) {
case '[object Date]':
return encodeURIComponent(obj.getFullYear() + '-' +
(obj.getMonth() + 1) + '-' +
obj.getDate() + ' ' +
obj.getHours() + ':' +
obj.getMinutes() + ':' +
obj.getSeconds() + '.' +
obj.getMilliseconds());
case '[object RegExp]':
return encodeURIComponent(obj.toString().replace('\0', '\0\0'));
case '[object Array]':
var arr = [];
for (var i in obj)
arr.push(arguments.callee(obj));
return arr.join(',');
case '[object Object]':
return '[object Object]';
}
break;
}
}
var arr = [];
for (var i = 0; i < args.length; i++) {
arr.push(getStr(args));
}
url = window.location.href;
var req = blqw.Ajax.GetRequest();
req.open('POST', url, false);
req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
var ret = req.send('blqw.ajaxdata=' + arr.join('\0') + '&blqw.ajaxmethod=' + method);
if (req.status == 200) {
var html = req.responseText;
var data = eval('(' + html+ ')');
if ('v' in data) {
eval(data.v);
}
if ('e' in data) {
throw blqw.Ajax.Throw(data.e);
} else {
return data.d;
}
} else {
alert('出现错误');
}
}
window.GetString=function(){return blqw.Ajax.Exec('GetString',arguments);}