JQuery中ajax方法訪問(wèn)web服務(wù)實(shí)例
本文實(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ù)他們的。 最后重要的是: 類上方添加的 [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ù)名稱 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)文章
jQuery控制input只能輸入數(shù)字和兩位小數(shù)的方法
這篇文章主要介紹了jQuery控制input只能輸入數(shù)字和兩位小數(shù)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-05-05
jquery中toggle函數(shù)交替使用問(wèn)題
jQuery 的toggle()函數(shù)使用show()或hide()函數(shù)來(lái)切換HTML元素的可見狀態(tài)。今天我們來(lái)探討下jquery中toggle函數(shù)交替使用問(wèn)題2015-06-06
jQuery插件DataTables分頁(yè)開發(fā)心得體會(huì)
這篇文章主要為大家分享了jQuery插件DataTables分頁(yè)開發(fā)心得體會(huì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
用js實(shí)現(xiàn)的模擬jquery的animate自定義動(dòng)畫(2.5K)
模仿jquery的animate寫了一個(gè)簡(jiǎn)單的動(dòng)畫實(shí)現(xiàn)方法。2010-07-07
jQuery選中select控件 無(wú)法設(shè)置selected的解決方法
select 控件的 option用jQuery動(dòng)態(tài)添加,然后選中某項(xiàng)時(shí),IE6不能執(zhí)行(火狐沒問(wèn)題),用try{}catch(err){alert(err.description);}提示為“無(wú)法設(shè)置selected屬性 未指明的錯(cuò)誤”2010-09-09
文本框水印提示效果的簡(jiǎn)單實(shí)現(xiàn)代碼
本篇文章主要是對(duì)文本框水印提示效果的簡(jiǎn)單實(shí)現(xiàn)代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02
JS秒殺倒計(jì)時(shí)功能完整實(shí)例【使用jQuery3.1.1】
這篇文章主要介紹了JS秒殺倒計(jì)時(shí)功能,結(jié)合完整實(shí)例形式分析了基于jQuery3.1.1基于時(shí)間函數(shù)的頁(yè)面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-09-09
各式各樣的導(dǎo)航條效果css3結(jié)合jquery代碼實(shí)現(xiàn)
這篇文章主要為大家分享了css3結(jié)合jquery代碼實(shí)現(xiàn)各式各樣的導(dǎo)航條效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-09-09

