国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

js跨域調用WebService的簡單實例

2024-05-06 16:32:28
字體:
來源:轉載
供稿:網友

步驟1.   在web.config中的system.web節點里加入

<!--此節點可允許腳本跨域調用webservice-->  <webServices>   <protocols>    <add name="HttpPost"/>    <add name="HttpGet"/>   </protocols>  </webServices>  <!--此節點可允許腳本跨域調用webservice-->

步驟2. webservice代碼

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.Web.Mvc;namespace WebService{  /// <summary>  /// WebService1 的摘要說明  /// </summary>  [WebService(Namespace = "http://tempuri.org/")]  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]  [System.ComponentModel.ToolboxItem(false)]  // 若要允許使用 ASP.NET AJAX 從腳本中調用此 Web 服務,請取消對下行的注釋。  [System.Web.Script.Services.ScriptService]  public class WebService1 : System.Web.Services.WebService  {    [ValidateInput(false)]    [WebMethod(Description = "測試")]    public void getDBTableInfos(string EnterpriseCode)    {      HttpContext.Current.Response.ContentType = "application/json;charset=utf-8";      string jsonCallBackFunName = string.Empty;      jsonCallBackFunName = HttpContext.Current.Request.Params["jsoncallback"].ToString();      HttpContext.Current.Response.Write(jsonCallBackFunName + "({ /"Result/": /"" + EnterpriseCode + "/" })");    }   }} 

步驟3. html頁面部分

<!DOCTYPE html><html><head>  <title>Index</title>  <script src="http://www.cnblogs.com/Scripts/jquery-1.5.1.js" type="text/javascript"></script>  <script type="text/javascript">    $(function () {      $("#btnSubmit").click(function () {        var EnterpriseCode = "39"; //企業代碼                var dataStr = "EnterpriseCode=" + EnterpriseCode;        $.ajax({          type: "get",          url: "http://xxx/xxx.asmx/AntiWebQuery_Ajax?jsoncallback?",          dataType: "jsonp",          jsonp: 'jsoncallback',          data: dataStr,          success: function (result) {            //返回結果            alert(result.Result);          }        });      });    });  </script></head><body>  <div>    <input id="btnSubmit" type="button" value="查詢" />  </div></body></html> 

以上就是小編為大家帶來的js跨域調用WebService的簡單實例的全部內容了,希望對大家有所幫助,多多支持VeVb武林網~


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 古交市| 鄄城县| 梁平县| 无极县| 扶绥县| 兴仁县| 萝北县| 诸暨市| 池州市| 金山区| 嫩江县| 连城县| 平阳县| 新疆| 鸡西市| 荥经县| 新津县| 芜湖县| 武邑县| 靖西县| 白河县| 双城市| 东台市| 德保县| 体育| 高淳县| 泰州市| 高碑店市| 抚顺市| 阿勒泰市| 左云县| 营山县| 广丰县| 临漳县| 安化县| 富平县| 图木舒克市| 金秀| 正宁县| 屏东县| 荥经县|