第一次提交
This commit is contained in:
413
tomcat/webapps/sm/script/ajax.js
Normal file
413
tomcat/webapps/sm/script/ajax.js
Normal file
@@ -0,0 +1,413 @@
|
||||
//XML Request <20><><EFBFBD><EFBFBD>ͬһ<CDAC><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
//@req newXMLHttpRequest<73><74><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>
|
||||
//@responseXmlHandler <20>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
|
||||
//@exceptionHandler <20><><EFBFBD><EFBFBD>ʧ<EFBFBD>ܴ<EFBFBD><DCB4><EFBFBD><EFBFBD>Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD>alert<72><74><EFBFBD><EFBFBD>
|
||||
function getReadyStateHandler(req, responseXmlHandler, exceptionHandler)
|
||||
{
|
||||
return function ()
|
||||
{
|
||||
if (req.readyState == 4)// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4>ǡ<EFBFBD><C7A1><EFBFBD><EFBFBD>ɡ<EFBFBD>
|
||||
{
|
||||
var message = null;
|
||||
if (req.status == 200)
|
||||
{
|
||||
var xml = req.responseXML;
|
||||
if (xml == null)
|
||||
{
|
||||
message = "<22><><EFBFBD>صIJ<D8B5><C4B2>ǺϷ<C7BA><CFB7><EFBFBD>XML<4D><4C><EFBFBD><EFBFBD>" + req.responseText;
|
||||
}
|
||||
else
|
||||
{
|
||||
var redirect = xml.getElementsByTagName("redirect");
|
||||
if (redirect && redirect.length)
|
||||
{
|
||||
window.location.href = redirect[0].getAttribute("href");
|
||||
return;
|
||||
}
|
||||
var result = xml.getElementsByTagName("result")[0];
|
||||
if (result == null || "true" == result.getAttribute("status"))
|
||||
{
|
||||
responseXmlHandler(result, req);
|
||||
return;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
message = result.getAttribute("exception");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (req.status == 12029 || req.status == 0)
|
||||
{
|
||||
message = "<22><><EFBFBD>粻ͨ";
|
||||
}
|
||||
else if (req.status == 12030)
|
||||
{
|
||||
message = "<22><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˢ<EFBFBD><CBA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
}
|
||||
else if (req.status == 404)
|
||||
{
|
||||
message = "<22><><EFBFBD><EFBFBD>ҳ<EFBFBD>治<EFBFBD><E6B2BB><EFBFBD><EFBFBD>" + req.status;
|
||||
}
|
||||
else if (req.status == 500)
|
||||
{
|
||||
message = "<22><>̨<EFBFBD><CCA8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>";
|
||||
}
|
||||
else
|
||||
{
|
||||
message = "<22><>Ԥ֪<D4A4><D6AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + req.status;
|
||||
}
|
||||
if(exceptionHandler)
|
||||
{
|
||||
exceptionHandler(message, req.responseText);
|
||||
}
|
||||
else
|
||||
{
|
||||
finishProcess();
|
||||
if (message == null)
|
||||
{
|
||||
message = req.responseText;
|
||||
}
|
||||
alert(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XML HttpRequest
|
||||
function newXMLHttpRequest()
|
||||
{
|
||||
if (window.XMLHttpRequest) return new XMLHttpRequest();
|
||||
else return new ActiveXObject("Msxml2.XMLHTTP");
|
||||
}
|
||||
|
||||
function convertParameter(value)
|
||||
{
|
||||
if (value.indexOf("%") >= 0)
|
||||
value = value.replace(/\%/g, "%25");
|
||||
if (value.indexOf("&") >= 0)
|
||||
value = value.replace(/&/g, "%26");
|
||||
if (value.indexOf("=") >= 0)
|
||||
value = value.replace(/=/g, "%3d");
|
||||
if (value.indexOf(" ") >= 0)
|
||||
value = value.replace(/\ /g, "%20");
|
||||
if (value.indexOf("?") >= 0)
|
||||
value = value.replace(/\?/g, "%3f");
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* <20>ύ<EFBFBD>첽XMLRequest<73><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param postPage <20><><EFBFBD><EFBFBD>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>ַ
|
||||
* @param postArgumentArray <20><><EFBFBD><EFBFBD>ҳ<EFBFBD>洫<EFBFBD>ݵIJ<DDB5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD>顣
|
||||
* <20><> <20><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>ֵ...[<5B><><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E>ֵ]
|
||||
* @param responseXmlHandler <20><><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD>ص<EFBFBD><D8B5>ĺ<EFBFBD><C4BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param exceptionHandler <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳<EFBFBD><CCB3>ִ<EFBFBD><D6B4><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
*/
|
||||
function postRequest(postPage, postArgumentArray, responseXmlHandler, exceptionHandler)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!prepareProcessWindow("postProgress"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var req = newXMLHttpRequest();
|
||||
var exceptionHandle = exception;
|
||||
if (exceptionHandler && typeof(exceptionHandler) == "function")
|
||||
{
|
||||
exceptionHandle = exceptionHandler;
|
||||
}
|
||||
//alert(exceptionHandle);
|
||||
var handlerFunction = getReadyStateHandler(req, responseXmlHandler, exceptionHandle);
|
||||
req.onreadystatechange = handlerFunction;
|
||||
req.open("POST", postPage, true);
|
||||
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
||||
var postArgumentList = "";
|
||||
for (var i = 0; i < postArgumentArray.length/2; i++)
|
||||
{
|
||||
var name = convertParameter(postArgumentArray[i*2]);
|
||||
var value = convertParameter(postArgumentArray[i*2 + 1]);
|
||||
if (i > 0) postArgumentList += "&";
|
||||
postArgumentList += name + "=" + value;
|
||||
}
|
||||
req.send(postArgumentList);
|
||||
postArgumentList = null;
|
||||
setTimeout('showProgress("<22><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>......")', 2000);
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
finishProcess();
|
||||
exceptionHandle("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + e.name + "<22><>" + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function exception(info, detail)
|
||||
{
|
||||
finishProcess();
|
||||
if (info) alert(info);
|
||||
else if (detail) alert(detail);
|
||||
}
|
||||
|
||||
//<2F>жϲ<D0B6><CFB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
function isArray(a)
|
||||
{
|
||||
if(a && a.length
|
||||
&& Object.prototype.toString.apply(a).indexOf('[object ') >= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//<2F><><EFBFBD><EFBFBD>form<72><6D>ij<EFBFBD><C4B3>input<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
|
||||
function getFieldValue(a)
|
||||
{
|
||||
if (isArray(a))
|
||||
{
|
||||
for(var i = 0; i < a.length; i++)
|
||||
{
|
||||
if (a[i].checked)
|
||||
{
|
||||
return a[i].value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
else if (a && a.value)
|
||||
{
|
||||
return a.value;
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
function focusInput(x)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (x)
|
||||
{
|
||||
if(isArray(x) && x[0])
|
||||
{
|
||||
if (x[0].select) x[0].select();
|
||||
x[0].focus();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (x.select) x.select();
|
||||
x.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{
|
||||
//alert(e);
|
||||
}
|
||||
}
|
||||
|
||||
function getElements(parentNode, subNodeTagName)
|
||||
{//getElementsByTagName<6D><65>IE/Chrome<6D><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>֧<EFBFBD><D6A7>
|
||||
return parentNode.getElementsByTagName(subNodeTagName);
|
||||
}
|
||||
|
||||
function getElementAt(parentNode, subNodeTagName, index)
|
||||
{
|
||||
return getElements(parentNode, subNodeTagName)[index];
|
||||
}
|
||||
|
||||
var msg = new Object();
|
||||
|
||||
msg.busyMark = false;
|
||||
|
||||
msg.createDialog=function(id, isModal)
|
||||
{
|
||||
var dialog = document.createElement("div");
|
||||
dialog.className='dialog';
|
||||
dialog.id=id;
|
||||
|
||||
var titleBar=document.createElement("div");
|
||||
titleBar.className='titleBar';
|
||||
var closeButton=document.createElement("span");
|
||||
closeButton.dialog=dialog;
|
||||
closeButton.onclick=msg.hideDialog;
|
||||
closeButton.className='titleButton';
|
||||
var closeTxt=document.createTextNode("X");
|
||||
closeButton.appendChild(closeTxt);
|
||||
titleBar.appendChild(closeButton);
|
||||
dialog.appendChild(titleBar);
|
||||
|
||||
var tbl=document.createElement("table");
|
||||
dialog.appendChild(tbl);
|
||||
dialog.tbod=document.createElement("tbody");
|
||||
tbl.appendChild(dialog.tbod);
|
||||
|
||||
if (isModal)
|
||||
{
|
||||
dialog.modalLayer=document.createElement("div");
|
||||
dialog.modalLayer.className='modal';
|
||||
dialog.modalLayer.style.display='none';
|
||||
dialog.modalLayer.appendChild(dialog);
|
||||
document.body.appendChild(dialog.modalLayer);
|
||||
}
|
||||
else
|
||||
{
|
||||
dialog.className+= ' non-modal';
|
||||
dialog.style.diaplay='none';
|
||||
document.body.appendChild(dialog);
|
||||
}
|
||||
return dialog;
|
||||
}
|
||||
|
||||
msg.hideDialog=function(e)
|
||||
{
|
||||
var dialog=this.dialog?this.dialog:msg.dialog;
|
||||
if (dialog)
|
||||
{
|
||||
if (dialog.modalLayer)
|
||||
{
|
||||
dialog.modalLayer.style.display='none';
|
||||
}
|
||||
else
|
||||
{
|
||||
dialog.style.diaplay='none';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg.showDialog=function(e)
|
||||
{
|
||||
var dialog=this.dialog?this.dialog:msg.dialog;
|
||||
if (dialog)
|
||||
{
|
||||
if (dialog.modalLayer)
|
||||
{
|
||||
dialog.modalLayer.style.display='block';
|
||||
}
|
||||
else
|
||||
{
|
||||
dialog.style.diaplay='block';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
msg.showMessage=function(message, el)
|
||||
{
|
||||
if (!el) el = msg.dialog.tbod;
|
||||
var inTable=(el.tagName=="TBODY");
|
||||
var topEl = null;
|
||||
var row = document.createElement("tr");
|
||||
if (!inTable)
|
||||
{
|
||||
topEl=document.createElement("table");
|
||||
var tbod=document.createElement("tbody");
|
||||
topEl.appendChild(tbod);
|
||||
tbod.appendChild(row);
|
||||
}
|
||||
else
|
||||
{
|
||||
topEl = row;
|
||||
}
|
||||
var txtTd=document.createElement("td");
|
||||
txtTd.valign="top";
|
||||
txtTd.className="msg_text";
|
||||
row.appendChild(txtTd);
|
||||
row = null;
|
||||
txtTd.innerHTML=message;
|
||||
DM.clearChildNodes(el);
|
||||
el.appendChild(topEl);
|
||||
}
|
||||
|
||||
function prepareProcessWindow(id)
|
||||
{
|
||||
msg.dialog = $(id);
|
||||
if (!msg.dialog)
|
||||
{
|
||||
msg.dialog = msg.createDialog(id, true);
|
||||
}
|
||||
if (msg.busyMark)
|
||||
{
|
||||
msg.showDialog();
|
||||
msg.showMessage("<22><><EFBFBD><EFBFBD>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>δִ<CEB4><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
msg.busyMark = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function showProgress(message)
|
||||
{
|
||||
if (msg.busyMark)
|
||||
{
|
||||
msg.showDialog();
|
||||
msg.showMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
function $(id)
|
||||
{
|
||||
return document.getElementById(id);
|
||||
}
|
||||
|
||||
function hideDiv(id)
|
||||
{
|
||||
var t;
|
||||
if (id.length) t = $(id);
|
||||
else t = id;
|
||||
t.style.display="none";
|
||||
}
|
||||
|
||||
function displayBlockDiv(id)
|
||||
{
|
||||
var t;
|
||||
if (id.length) t = $(id);
|
||||
else t = id;
|
||||
t.style.display="block";
|
||||
}
|
||||
|
||||
function finishProcess(id)
|
||||
{
|
||||
if (this.busyMark)
|
||||
{
|
||||
this.busyMark = false;
|
||||
}
|
||||
if (msg != null)
|
||||
{
|
||||
if (msg.busyMark)
|
||||
{
|
||||
msg.busyMark = false;
|
||||
}
|
||||
msg.hideDialog();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var DM = new Object();
|
||||
|
||||
DM.clearChildNodes = function(dom)
|
||||
{
|
||||
this.tmpDom = null;
|
||||
|
||||
while (dom && dom.lastChild)
|
||||
{
|
||||
this.tmpDom = dom.removeChild(dom.lastChild);
|
||||
if (this.tmpDom.refs)
|
||||
{//used in IE
|
||||
for (var i in this.tmpDom.refs)
|
||||
{
|
||||
if (this.tmpDom.refs[i].parentNode)
|
||||
{
|
||||
var tmpChildDom = this.tmpDom.refs[i].parentNode.removeChild(this.tmpDom.refs[i]);
|
||||
delete this.tmpChildDom;
|
||||
delete tmpDom.refs[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
delete this.tmpDom;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user