Access the web service instance through ajax in JQuery _ jquery-js tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.