1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //数据库查询类
- function WsCommonClass( method, variable, value, callbackFun,keyValue,url) {
- var _url ; //请求地址
- var _method = method; //方法名
- var _variable = variable; //变量名数组
- var _value = value; //变量数组
- if(isEmptyValue(xmlUtil))
- GetConfigData();
- var webServiceXml = xmlDoc.getElementsByTagName("WebServiceURL");
- _url = url;
- if (_variable.length != _value.length) {
- return "参数不正确!";
- }
- //设置访问的字符串
- var data = "";
- data += '<?xml version="1.0" encoding="utf-8"?>';
- data += '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
- data += '<soap:Body>';
- data += '<' + _method + ' xmlns="http://tempuri.org/">';
- for (var i = 0; i < _variable.length; i++) {
- data += '<' + _variable[i] + '>' + _value[i] + '</' + _variable[i] + '>';
- }
- data = data + '</' + _method + '>';
- data = data + '</soap:Body>';
- data = data + '</soap:Envelope>';
- var xmlhttp;
- try {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- }
- catch (e) {
- try {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- }
- catch (e) {
- xmlhttp = new XMLHttpRequest();
- }
- }
- //设置通讯请求的方式
- if (xmlhttp != null && xmlhttp != "undefind") {
- try{
- xmlhttp.open("POST", _url,false);
- }
- catch (e){
- try{
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.open("POST", _url,false);
- }
- catch (e) {
- xmlhttp = new XMLHttpRequest();
- xmlhttp.open("POST", _url,false);
- }
- }
- }
- else {
- return "发生错误";
- }
- xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
- xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/" + _method);
- try {
- //获取放回结果并传递给调用者
- xmlhttp.onreadystatechange = function () {
- var xmlDoc = xmlhttp.responseXML;
- var data = xmlDoc.getElementsByTagName(_method + "Result");
- var result = data;//[0].childNodes[0].textContent;
- if (callbackFun)
- callbackFun(result,keyValue);
- };
- xmlhttp.send(data);
- }
- catch (e) {
- $('#myloading').modal('close');
- alert("请求失败!");
- }
- }
|