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
                }
            }
            );

 

转载于:https://www.cnblogs.com/hellohongfu/archive/2012/10/10/2718060.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
版本号:v1.0 创建人:王国胜 版本创建日期:2011-03-30 相关知识点说明:此测试程序包含JsonWebserviceJquery、Ajax相关知识 引用程序集:Newtonsoft.Json.Net35 文件夹及文件说明: JsonDemo\ 应用Newtonsoft相关用例文件夹 ContractResolver.aspx 传入泛型类并序列化为Json格式数据 CustomCreationConverter.aspx 传入Json转化为泛型类 DateTime_JsonConverters.aspx Json中的日期时间转换 PreserveObjectReferences.aspx Json序列化泛型集合时得到两个相同的对象时,第二个引用第一个 PreserveReferencesHandling.aspx Json序列化泛型集合时得到两个相同的对象时,第二个引用第一个 ReadingWritingJSON.aspx 阅读和书写JSON ReducingSerializedJSONSize.aspx 序列化JSON的尺寸缩小 SelectToken.aspx 到JSON的LINQ查询与SelectToken SerializingCollections.aspx 序列化集合 SerializingJSON.aspx 序列化和反序列化的JSON,包含一些常用属性说明 SerializingJSONFragments.aspx 部分片段的序列化的JSON及查询 Scripts\ 常用javascript脚本文件夹 jquery-1.4.1-vsdoc.js jquery智能感知引用 jquery-1.4.1.js jquery一用文件 jquery-1.4.1.min.js jquery精简版 Styles\ 样式文件夹 Site.css 样式文件 Webservice\ Webservice接口文件夹 WebService.asmx Webservice文件 App_Code\ 常用类文件夹 CollectionHelper.cs List与DataTable相互转换类 JsonAndDateTable.cs Json与DataTable相互转换类 Default.aspx JsonWebserviceJquery、Ajax测试页

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值