⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlhttpclient.js

📁 电信的网厅的整站代码
💻 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 + -