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.
JS Code:
$. Ajax ({
Type: "POST ",
// Specify the returned Json
ContentType: "application/json; UTF-8 ",
// Collegedomainwebservices. 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 returned value is the ArrayList.
$. Each (result, function (I, n ){
// DdlDepart is the down menu. Add new options to the drop-down menu cyclically
DdlDepart. options [ddlDepart. length] = new Option (n. collegepartition title, n. CollegeDepartId );
});
}
}
Catch (e)
{
Alert ("error >>" + e. message );
Return;
}
},
Error: function (data)
{
Alert (data. status + ">>>" + data. statusText );
}
});
Collegedomainwebservices. asmx. cs
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
[ScriptService]
Public class collegedomainwebservices: System. Web. Services. WebService
{
Public collegedomainwebservices ()
{
// 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. getcollege1_listbycollegeid (int. Parse (strDepartId ));
Return myList;
}
}