WsCommonClass.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //数据库查询类
  2. function WsCommonClass( method, variable, value, callbackFun,keyValue,url) {
  3. var _url ; //请求地址
  4. var _method = method; //方法名
  5. var _variable = variable; //变量名数组
  6. var _value = value; //变量数组
  7. if(isEmptyValue(xmlUtil))
  8. GetConfigData();
  9. var webServiceXml = xmlDoc.getElementsByTagName("WebServiceURL");
  10. _url = url;
  11. if (_variable.length != _value.length) {
  12. return "参数不正确!";
  13. }
  14. //设置访问的字符串
  15. var data = "";
  16. data += '<?xml version="1.0" encoding="utf-8"?>';
  17. 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/">';
  18. data += '<soap:Body>';
  19. data += '<' + _method + ' xmlns="http://tempuri.org/">';
  20. for (var i = 0; i < _variable.length; i++) {
  21. data += '<' + _variable[i] + '>' + _value[i] + '</' + _variable[i] + '>';
  22. }
  23. data = data + '</' + _method + '>';
  24. data = data + '</soap:Body>';
  25. data = data + '</soap:Envelope>';
  26. var xmlhttp;
  27. try {
  28. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  29. }
  30. catch (e) {
  31. try {
  32. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  33. }
  34. catch (e) {
  35. xmlhttp = new XMLHttpRequest();
  36. }
  37. }
  38. //设置通讯请求的方式
  39. if (xmlhttp != null && xmlhttp != "undefind") {
  40. try{
  41. xmlhttp.open("POST", _url,false);
  42. }
  43. catch (e){
  44. try{
  45. xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  46. xmlhttp.open("POST", _url,false);
  47. }
  48. catch (e) {
  49. xmlhttp = new XMLHttpRequest();
  50. xmlhttp.open("POST", _url,false);
  51. }
  52. }
  53. }
  54. else {
  55. return "发生错误";
  56. }
  57. xmlhttp.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
  58. xmlhttp.setRequestHeader("SOAPAction", "http://tempuri.org/" + _method);
  59. try {
  60. //获取放回结果并传递给调用者
  61. xmlhttp.onreadystatechange = function () {
  62. var xmlDoc = xmlhttp.responseXML;
  63. var data = xmlDoc.getElementsByTagName(_method + "Result");
  64. var result = data;//[0].childNodes[0].textContent;
  65. if (callbackFun)
  66. callbackFun(result,keyValue);
  67. };
  68. xmlhttp.send(data);
  69. }
  70. catch (e) {
  71. $('#myloading').modal('close');
  72. alert("请求失败!");
  73. }
  74. }