• 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
                    }
                }
                );
  • 相关阅读:
    ARM的体系结构与编程系列博客——ARM体系版本
    eclipse快捷键
    ARM的体系结构与编程系列博客——ARM的历史与应用范围
    基于LINUX的多功能聊天室
    CC2530自动安全联网
    python3元组
    Python3 列表
    Python3 数字(Number)
    Python3 注释
    python3解释器
  • 原文地址:https://www.cnblogs.com/hellohongfu/p/2718060.html
Copyright © 2020-2023  润新知