• ajax调用webservice服务


    ajax调用是 html方向调用的, 而sqlconnection是 java代码调用的,本质差不多

     1 <html>
     2     <head>
     3         <title>通过ajax调用webservice服务</title>
     4         <script>
     5             var xhr;
     6             function sendAjaxWS(){
     7                 xhr = new ActiveXObject("Microsoft.XMLHTTP");
     8                 //指定ws的请求地址
     9                 var wsUrl = "http://192.168.1.108:5678/hello";
    10                 //手动构造请求体
    11                 var requestBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" ' + 
    12                                     ' xmlns:q0="http://service.itcast.cn/" xmlns:xsd="http://www.w3.org/2001/XMLSchema "'+
    13                                     ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
    14                                     '<soapenv:Body><q0:sayHello><arg0>'+document.getElementById("msg").value+'</arg0> <arg1>10</arg1> </q0:sayHello></soapenv:Body></soapenv:Envelope>';
    15                 //打开连接
    16                 xhr.open("POST",wsUrl,true);
    17                 //重新设置请求头
    18                 xhr.setRequestHeader("content-type","text/xml;charset=utf8");
    19                 //设置回调函数
    20                 xhr.onreadystatechange = _back;
    21                 //发送请求
    22                 xhr.send(requestBody);
    23             }
    24 
    25             //定义回调函数
    26             function _back(){
    27                 if(xhr.readyState == 4){
    28                     if(xhr.status == 200){
    29                         var ret = xhr.responseXML;
    30                         //解析xml
    31                         var eles = ret.getElementsByTagName("return")[0];
    32                         alert(eles.text);
    33                     }
    34                 }
    35             }
    36         </script>
    37     </head>
    38     <body>
    39         <input type="text" id="msg" />
    40         <input type="button" onclick="sendAjaxWS();" value="通过ajax调用webservice服务"/>
    41     </body>
    42 </html>
  • 相关阅读:
    跨数据库操作
    Windows 服务
    Linq To DataTable
    嵌入式软件应用程序开发框架浅见
    31.获取当前系统时间
    30 System类
    29. StringBuilder
    28. string类中方法练习
    27 string类中常用的方法列表
    26.String类(1)
  • 原文地址:https://www.cnblogs.com/friends-wf/p/3805607.html
Copyright © 2020-2023  润新知