老系统对接
This commit is contained in:
123
webapp/js/ajaxHelper.js
Normal file
123
webapp/js/ajaxHelper.js
Normal file
@ -0,0 +1,123 @@
|
||||
|
||||
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("<22><><EFBFBD>ܷ<EFBFBD><DCB7>ʷ<EFBFBD><CAB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD><EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1>")
|
||||
};
|
||||
|
||||
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//
|
||||
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user