欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery中ajax方法訪問(wèn)web服務(wù)實(shí)例

 更新時(shí)間:2015年07月18日 11:52:45   作者:鑒客  
這篇文章主要介紹了JQuery中ajax方法訪問(wèn)web服務(wù)的方法,實(shí)例分析了jquery中Ajax方法結(jié)合asp.net程序處理web訪問(wèn)的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

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

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

jquery代碼部分:

$.ajax({
type: "POST",
//注明 返回Json
contentType:"application/json;utf-8",
//CollegeDepartWebServices.asmx web服務(wù)名 /GetCollegeDepart 方法名
url:"CollegeDepartWebServices.asmx/GetCollegeDepart",
//strDepartId 參數(shù)名稱(chēng) collegeId 參數(shù)值
data:"{strDepartId:"+collegeId+"}",
dataType:"json",
success:function(result){          
  var json=null
   try
    {
    if(result)
    {
      //因?yàn)榉祷氐氖茿rrayList 所以循環(huán)取出其中的值
      $.each(result, function(i, n){
      //ddlDepart 為下來(lái)菜單。循環(huán)的向下拉菜單中添加新的選項(xiàng)
      ddlDepart.options[ddlDepart.length]=new Option(n.CollegeDepartTitle,n.CollegeDepartId);
      });
    }
    }
    catch(e)
    {
     alert("錯(cuò)誤>>"+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()
  {
    //如果使用設(shè)計(jì)的組件,請(qǐng)取消注釋以下行 
    //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;
  }
}

希望本文所述對(duì)大家的jquery程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論