/* 此方法为Ajax 调用Java Axis的web服务,调用举例如下:
callAxisWsPost("远程方法名", new Array("参数名1","参数名2"...), new Array(参数值1,参数值2...),
"wsdl地址",
"命名空间", function (result) {
//Ajax完成后的回调处理,result为服务端返回结果
}, function () {
//Ajax加载时的处理,如弹出loading遮罩层,提交按钮禁用等
});
*/
function callAxisWsPost(method, variable, value, url, _Namespace, callback, loadProcess) {
function getlen(str) {
var bytesCount = 0;
for (var i = 0; i < str.length; i++) {
var c = str.charAt(i);
if (/^[\u0000-\u00ff]$/.test(c)) //匹配双字节
{
bytesCount += 1;
}
else {
bytesCount += 2;
}
}
return bytesCount;
}
var xmlhttp = null;
if (window.ActiveXObject) {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
}
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = 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 = data + '<soap:Body>';
data = data + '<' + method + ' xmlns="' + _Namespace + '">';
for (var i = 0; i < variable.length; i++) {
data = data + '<' + variable[i] + '>' + value[i] + '</' + variable[i] + '>';
}
data = data + '</' + method + '>';
data = data + '</soap:Body>';
data = data + '</soap:Envelope>';
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 1) {
if (loadProcess)
loadProcess();
}
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
if (callback)
callback(xmlhttp.responseText);
}
}
}
xmlhttp.Open("POST", url, true);
xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.SetRequestHeader("Content-Length", getlen(data));
xmlhttp.SetRequestHeader("SOAPAction", _Namespace + method);
xmlhttp.Send(data);
}
具体的调用举例
callAxisWsPost("getPoleByLineid", new Array("lineid"), new Array(record.data.transLinId),
"http://192.168.1.129:8005/axis2/services/SimpleService?wsdl",
"http://ws.apache.org/axis2", function (result) {
var XmlDoc = getXmlDom(result);
var returns = XmlDoc.getElementsByTagName("return");
var poleStr = returns[0].childNodes[0].nodeValue;
var poleInfoArray = poleStr.split(";");
for (var i = 0; i < poleInfoArray.length - 1; i++) {
var poleInfos = poleInfoArray[i].split(",");
var id = poleInfoArray[i];
var name = poleInfos[0];
transStartArray[i] = [id, name];
transEndArray[i] = [id, name];
}
ComboTowerStart.clearValue();
ComboTowerStart.store.removeAll();
ComboTowerEnd.clearValue();
ComboTowerEnd.store.removeAll();
ComboTowerStart.store.loadData(transStartArray);
var towerStartId = ComboTowerStart.store.getAt(0).get('towerStartId'); //默认选中第一个
ComboTowerStart.setValue(towerStartId);
ComboTowerEnd.store.loadData(transEndArray);
var towerEndId = ComboTowerEnd.store.getAt(0).get('towerEndId'); //默认选中第一个
ComboTowerEnd.setValue(towerEndId);
Efs.getExt('btnLinesFlightOk').enable();
}, function () {
Efs.getExt('btnLinesFlightOk').disable();
});