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 } } );
posted on 2012-10-10 11:51 HelloHongfu 阅读(2038) 评论(0) 编辑 收藏 举报