zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    文档撰写思路与排版(hadoop)
    ULUA的简洁用法(二)
    开源cocos2d-x编辑器 qco-editor
    u3d tolua + ZeroBraneStudio远程调试
    ULUA的简洁用法
    OpenGL顶点数据传输速度优化
    在do while语句中使用continue的误解
    cocos2d-x 3D shader的纹理坐标是上下颠倒的
    使用ndk-gdb调试android native程序
    OpenSSL中AES加密的用法
  • 原文地址:https://www.cnblogs.com/friends-wf/p/3805607.html
Copyright © 2011-2022 走看看