关于Ajax请求WebService
1、前台脚本
1 <script type="text/javascript" language="javascript"> 2 var url = window.location.protocol + "//" + window.location.host; 3 if (window.location.port != "") { 4 url += ":" + window.location.port 5 } 6 7 var strUrl = url + "/WebService/OAService.asmx/EncryptDES"; 8 $.ajax({ 9 async: false, 10 type: "POST", 11 url: strUrl, 12 data: "{encryptString:'powerpip'}", 13 dataType: "json", 14 contentType: "application/json; charset=utf-8", 15 success: function (result) { 16 17 dataResult = result.d; alert(dataResult); 18 }, 19 error: function (XMLHttpRequest) { 20 alert("error"); 21 } 22 }); 23 24 25 </script>
2、WebService
1 // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 2 [System.Web.Script.Services.ScriptService] 3 4 /// <summary> 5 /// DES加密字符串 6 /// </summary> 7 /// <param name="loginname"></param> 8 /// <returns></returns> 9 [WebMethod(Description = "DES加密字符串")] 10 public string EncryptDES(string encryptString) 11 { 12 ComOp com = new ComOp(); 13 14 return com.EncryptDES(encryptString, com.EncryptKey); 15 }
3、Web.Config
<system.web>
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
</system.web>

浙公网安备 33010602011771号