zoukankan      html  css  js  c++  java
  • JS,Jquery 调用 C#WebService

    1,需要在服务下面把代码的注释去掉

      // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
      //[System.Web.Script.Services.ScriptService]

    2,JS 调用方法如下

    var request = '<?xml version="1.0" encoding="utf-8"?>';
                request += '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">'
                request += '<soap12:Body>'
                request += '<UpdateFacultativere xmlns="http://tempuri.org/">'
                request += '   <facNum>12313</facNum>'
                request += '  <facVerstion>2</facVerstion>'
                request += '   <date>string</date>'
                request += ' <description>string</description>'
                request += ' </UpdateFacultativere>'
                request += '</soap12:Body>'
                request += '</soap12:Envelope>'
    
                var req = new XMLHttpRequest();
                req.open("POST", 'http://localhost:34869/CRMService.asmx', true)
                // Responses will return XML. It isn't possible to return JSON.
                //req.setRequestHeader("Accept", "application/xml, text/xml, */*");
                req.setRequestHeader("Content-Type", "application/soap+xml; charset=utf-8");
                req.setRequestHeader("Content-Length:", request.length);
    
                req.setRequestHeader("SOAPAction", "http://tempuri.org/UpdateFacultativere");
                req.onreadystatechange = function () { DoR(req, successCallback, errorCallback); };
                req.send(request);
    

      

    3,Jquery调用方法如下

                $.ajax({
                    url: 'http://localhost:34869/CRMService.asmx/UpdateFacultativere',
                    data: {facNum :'02020',facVerstion:10, date:'10292', description:'2222'},
                    dataType: "xml",
                    type: "POST",
                    success: function (xml) {
                        debugger
                        alert(xml);
                    },
                    error: function (xml, status) { 
                        debugger
                    }
                }
                );
  • 相关阅读:
    PB数据窗口分页
    Oracle创建视图权限不足
    PB计算两个日期相差月份(计算工龄)
    oracle笔记之计算年龄、工龄和TRUNC
    oracle随笔之提示“ORA-01002: 提取违反顺序”
    PB笔记之调用数据窗口时的过滤条件添加方式
    Oracle随笔之用拆分后的列数据关联表查询
    四种布局
    Android控件常见属性
    Activity启动活动最佳写法
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2718060.html
Copyright © 2011-2022 走看看