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

首頁 > 編程 > JavaScript > 正文

JQuery中ajax方法訪問web服務實例

2019-11-20 12:01:40
字體:
來源:轉載
供稿:網友

本文實例講述了JQuery中ajax方法訪問web服務。分享給大家供大家參考。具體分析如下:

說明: ArrayList 中 存為對象CollegeDepartInfo 其屬性為:stirng CollegeDepartTitle 和 int CollegeDepartId 在javascript中 ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId); Option的參數就是依據他們的。 最后重要的是: 類上方添加的 [ScriptService] 必須添加,否則ajax無法調用WebService

jquery代碼部分:

$.ajax({type: "POST",//注明 返回JsoncontentType:"application/json;utf-8",//CollegeDepartWebServices.asmx web服務名 /GetCollegeDepart 方法名url:"CollegeDepartWebServices.asmx/GetCollegeDepart",//strDepartId 參數名稱 collegeId 參數值data:"{strDepartId:"+collegeId+"}",dataType:"json",success:function(result){            var json=null   try    {    if(result)    {      //因為返回的是ArrayList 所以循環取出其中的值      $.each(result, function(i, n){      //ddlDepart 為下來菜單。循環的向下拉菜單中添加新的選項      ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId);      });    }    }    catch(e)    {     alert("錯誤>>"+e.message);     return;    }   },   error:function(data)   {   alert(data.status+">>> "+data.statusText);   }}); 

CollegeDepartWebServices.asmx.cs部分:

[WebService(Namespace = "http://tempuri.org/")][WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)][ScriptService]public class CollegeDepartWebServices : System.Web.Services.WebService{  public CollegeDepartWebServices()  {    //如果使用設計的組件,請取消注釋以下行     //InitializeComponent();   }  [WebMethod]  [System.Xml.Serialization.XmlInclude(typeof(CollegeDepartInfo))]  public ArrayList GetCollegeDepart(string strDepartId)  {    CollegeDepartBL.FlushCollegeDepartCache();    if (string.IsNullOrEmpty(strDepartId))      return null;    ArrayList myList = CollegeDepartBL.GetCollegeDepartListByCollegeID(int.Parse(strDepartId));    return myList;  }}

希望本文所述對大家的jquery程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 象州县| 远安县| 石嘴山市| 内江市| 蒙城县| 武功县| 论坛| 公主岭市| 莒南县| 惠东县| 霍邱县| 霍州市| 巨鹿县| 陕西省| 呼伦贝尔市| 错那县| 彭泽县| 商南县| 清徐县| 安阳县| 敦煌市| 金门县| 茂名市| 同江市| 宜城市| 昌乐县| 平昌县| 昂仁县| 邵阳县| 江永县| 常宁市| 商水县| 五华县| 喀喇沁旗| 多伦县| 安阳市| 喀喇沁旗| 临潭县| 临邑县| 凤翔县| 库尔勒市|