124 lines
2.9 KiB
JavaScript
124 lines
2.9 KiB
JavaScript
|
|
document.oncontextmenu = new Function("event.returnValue=false;");
|
|
/////////////////////////////////////////////////////
|
|
|
|
function sleep(timeout) {
|
|
window.showModalDialog("javascript:document.writeln('<script>window.setTimeout(function () { window.close(); }, " + timeout + ");<\/script>');");
|
|
}
|
|
|
|
function ajaxRequest(url,onSuccess){
|
|
|
|
new AjaxHelper.Request(
|
|
{
|
|
url : url,
|
|
method : 'get',
|
|
asynchronous : false,
|
|
onSuccess : function(_response ) {
|
|
|
|
onSuccess(_response);
|
|
|
|
}//onSuccess
|
|
});
|
|
}
|
|
|
|
function ajaxRequest(url,onSuccess,asynchronous){
|
|
|
|
new AjaxHelper.Request(
|
|
{
|
|
url : url,
|
|
method : 'get',
|
|
asynchronous : asynchronous,
|
|
onSuccess : function(_response ) {
|
|
|
|
onSuccess(_response);
|
|
|
|
}//onSuccess
|
|
});
|
|
}
|
|
/////////////////////////////
|
|
|
|
|
|
var AjaxHelper = {}
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
//Request
|
|
AjaxHelper.Request = function(config) {
|
|
|
|
|
|
var defaultSuccessFunction = function(){};
|
|
var defaultFailFunction = function(){
|
|
//alert("不能访问服务器,请联系开发维护人员!")
|
|
};
|
|
|
|
this.url = config.url ;
|
|
this.method = config.method || 'post';
|
|
this.asynchronous = config.asynchronous ;
|
|
this.contentType = config.contentType || 'application/x-www-form-urlencoded';
|
|
// this.encoding = config.encoding || 'UTF-8';
|
|
this.onSuccess = config.onSuccess || defaultSuccessFunction;
|
|
this.onFail = config.onFail || defaultFailFunction;
|
|
|
|
|
|
var transportObject = this.getTransportObject();
|
|
|
|
transportObject.onreadystatechange = this.getReadyStateHandler(transportObject,this);
|
|
|
|
transportObject.open(this.method, this.url, this.asynchronous);
|
|
transportObject.setRequestHeader("Content-Type", this.contentType);
|
|
transportObject.send();
|
|
|
|
};
|
|
|
|
AjaxHelper.Request.prototype = {
|
|
getTransportObject : function() {
|
|
var xmlreq = false;
|
|
if (window.XMLHttpRequest) {
|
|
xmlreq = new XMLHttpRequest();
|
|
|
|
} else if (window.ActiveXObject) {
|
|
try {
|
|
xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
|
|
} catch (e1) {
|
|
try {
|
|
xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
|
|
} catch (e2) {
|
|
xmlreq = false;
|
|
}
|
|
}
|
|
}
|
|
return xmlreq;
|
|
},
|
|
|
|
getReadyStateHandler:function(transportObject, ajaxRequest){
|
|
return function () {
|
|
var result = false;
|
|
|
|
if (transportObject.readyState == 4) {
|
|
|
|
if (transportObject.status == 200) {
|
|
//alert(transportObject.responseText);
|
|
ajaxRequest.onSuccess({
|
|
responseXML: transportObject.responseXML,
|
|
responseTEXT:transportObject.responseText
|
|
});
|
|
|
|
|
|
} else {
|
|
//alert(transportObject.status );
|
|
ajaxRequest.onFail();
|
|
|
|
}//status
|
|
|
|
ajaxRequest.transportObject = null; //clear XMLHttpRequest
|
|
}//readyState
|
|
|
|
|
|
|
|
return result;
|
|
}
|
|
}//getReadyStateHandler//
|
|
|
|
|
|
};
|
|
|