国产探花免费观看_亚洲丰满少妇自慰呻吟_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教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 资兴市| 惠水县| 杂多县| 茂名市| 黑河市| 三亚市| 抚松县| 榆林市| 察哈| 含山县| 尤溪县| 丹江口市| 比如县| 田阳县| 南召县| 社旗县| 二手房| 宜宾市| 陈巴尔虎旗| 贵南县| 醴陵市| 贵定县| 简阳市| 甘肃省| 普洱| 和平区| 柳林县| 桦川县| 怀集县| 长岛县| 福安市| 汉寿县| 廊坊市| 酉阳| 通渭县| 洛南县| 富蕴县| 克山县| 庆云县| 文登市| 武穴市|