This article mainly introduces the ajax method in JQuery to access web services. The example analyzes the Ajax method in jquery combined with the asp.net program to process web access, which has some reference value, for more information about how to use ajax in JQuery to access web services, see the following example. Share it with you for your reference. The specific analysis is as follows:
Note: The ArrayList object CollegeDepartInfo has the following attributes: stirng college0000title and int CollegeDepartId in javascript: ddlDepart. options [ddlDepart. length] = new Option (n. collegeappstitle, n. collegeDepartId); Option parameters are based on them. Finally, the [ScriptService] added above the class must be added. Otherwise, ajax cannot call WebService.
Jquery code:
$. Ajax ({type: "POST", // indicate the returned JsoncontentType: "application/json; UTF-8", // college#webservices. asmx web Service name/GetCollegeDepart method name url: "collegedomainwebservices. asmx/GetCollegeDepart ", // strDepartId parameter name collegeId parameter value data:" {strDepartId: "+ collegeId +"} ", dataType:" json ", success: function (result) {var json = null try {if (result) {// The value is retrieved cyclically because ArrayList is returned $. each (result, function (I, n) {// ddlDepart is the down menu . Add the new option ddlDepart to the drop-down menu cyclically. options [ddlDepart. length] = new Option (n. collegeappstitle, n. collegeDepartId) ;};}} catch (e) {alert ("error >>" + e. message); return ;}}, error: function (data) {alert (data. status + ">>>" + data. statusText );}});
Collegew.webservices. asmx. cs section:
[WebService (Namespace = "http://tempuri.org/")] [WebServiceBinding (ConformsTo = WsiProfiles. basicProfile1_1)] [ScriptService] public class college=webservices: System. web. services. webService {public collegewebwebservices () {// if you use the designed component, uncomment the following line // 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 ;}}
I hope this article will help you with jquery programming.