?? xmlhttpclient.js
字號:
/******************************************************************************
EXMPLE:
客戶端
try{
var x = new XMLHttpClient('url');
x.append('sParamServNbr','32323923');
var doc=x.submit();
var head = doc.childNodes.item(0);
var body = doc.childNodes.item(1);
var bLogin = body.childNodes.item(0).text;
var sServNbr = body.childNodes.item(1).text;
setServNbr(sServNbr);
var sUserName = body.childNodes.item(2).text;
setUserName(sUserName);
}catch(ex){
alert(ex.description);
}
}
******************************************************************************/
/**
* class XMLHttpClient
* @param url eg. http://192.168.0.94:8004/ejbApp/unccnew/service/candialout.jsp
* @param method eg. 'post', default is 'post'
* @param aysn default is false.
*/
function XMLHttpClient(url,method,aysn) {
this._url = (url == null) ? "" : url;
this._param = "";
this._method = (method == null) ? "post" : method;
this._aysn = (aysn == null) ? false : aysn;
this._xHttp = new ActiveXObject("Msxml2.XMLHTTP.3.0");
this.setUrl = function(url) {
if(url == null)return;
this._url = url;
}
this.setMethod = function(method) {
if(method == null)return;
this._method = method;
}
this.setAysn = function(aysn) {
if(aysn == null)return;
this._aysn = aysn;
}
this.append = function(key,value) {
if(key == null)
return;
if(value == null)
value = "";
this._param += "<form><name>";
this._param += key;
this._param += "</name><value>";
this._param += encodeURIComponent(value);
this._param += "</value></form>";
}
/**
* @auther janage
* @createDate 2004年11月11日
* @describe 將指定表單的所有域作為參數添加到XMLHttpClient中。
* @param formObj 表單對象。
*/
this.appendAllForms = function(formObj) {
var result = false;
try
{
if ( typeof(formObj) == undefined )
{
throw "沒有找到表單“Form”的定單,不能獲取相應的內容。";
}
// 添加所有表單元素的值。
var _tags = new Array(3);
_tags[0] = "input";
_tags[1] = "select";
_tags[2] = "textarea";
for ( var j = 0; j < _tags.length; j++ )
{
var _elements = formObj.all.tags(_tags[j]);
for ( var i = 0; i < _elements.length; i++ )
{
if ( j==0 && _elements[i].type=="radio" )
{
if ( _elements[i].checked )
this.append(_elements[i].name,_elements[i].value);
}
else
this.append(_elements[i].name,_elements[i].value);
}
}
result = true;
}
catch(ex) {
alert(ex);
}
return result;
}
this.submit = function(serviceName, methodName) {
if ( this._xHttp.readyState != 0 ) this._xHttp.abort();
if ( serviceName == null || serviceName == "" ) {
throw "沒有指定遠程調用服務名稱,不能調用遠程服務";
}
var sURL = "serviceName=" + serviceName;
sURL += "&methodName=" + methodName;
sURL += "&xmlParam=" + this._param;
this._xHttp.open(this._method,this._url,this._aysn);
this._xHttp.setRequestHeader("content-length",this._param.length);
this._xHttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
this._xHttp.send(sURL);
var xmlDoc = new ActiveXObject("Msxml.DOMDocument");
var root;
xmlDoc.async = false;
xmlDoc.loadXML(this._xHttp.responseText);
if (xmlDoc.parseError.errorCode != 0) {
var myErr = xmlDoc.parseError;
throw myErr;
} else {
root = xmlDoc.documentElement;
}
return root;
}
this.submitAsString = function(serviceName, methodName) {
if ( this._xHttp.readyState != 0 ) this._xHttp.abort();
if ( serviceName == null || serviceName == "" ) {
throw "沒有指定遠程調用服務名稱,不能調用遠程服務";
}
var sURL = "serviceName=" + serviceName;
sURL += "&methodName=" + methodName;
sURL += "&xmlParam=" + this._param;
this._xHttp.open(this._method,this._url,this._aysn);
this._xHttp.setRequestHeader("content-length",sURL.length);
this._xHttp.setRequestHeader("content-type","application/x-www-form-urlencoded");
this._xHttp.send(sURL);
return this._xHttp.responseText;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -