This section describes Article ,
Http://www.cnblogs.com/alvinyue/archive/2011/05/17/2048783.html
The previous article introduced how to obtain JSON data asynchronously from the foreground (there are many shortcomings. I hope the majority of users will correct me. Thank you !), This time introduces another method $. get (). Its prototype is jquery. get (URL, [data], [success (data, textstatus, jqxhr)], [datatype! As follows: About. cshtml $ ( Function (){
// Get the schools
$. Get ( " /Home/getschools " , Function (Data ){
$ (Data). Each ( Function (){
VaR O = Document. createelement ( " Option " );
O. Value = This [ ' ID ' ];
O. Text = This [ ' Name ' ];
$ ( " # Sltschool " )[ 0 ]. Options. Add (O );
});
});
// Get the credits depend on the school
$ ( " # Sltschool " ). Change ( Function (){
// Initialization the select
$ ( " # Sltdepartment " ). Empty ();
VaR _ O = Document. createelement ( " Option " );
_ O. Value = " -1 " ;
_ O. Text = " Select... " ;
$ ( " # Sltdepartment " )[ 0 ]. Options. Add (_ O );
$. Get ( " /Home/getdocumments " , {Schoolid: $ ( " # Sltschool " ). Val ()}, Function (Data ){
$ (Data). Each ( Function (){
VaR O = Document. createelement ( " Option " );
O. Value = This [ ' ID ' ];
O. Text = This [ ' Name ' ];
$ ( " # Sltdepartment " )[ 0 ]. Options. Add (O );
});
});
});
}); The following background method is called:Controller
Public Jsonresult getschools ()
{
Return This . JSON (testmodels. getallschools (), jsonrequestbehavior. allowget );
}
PublicJsonresult getdocumments (IntSchoolid)
{
ReturnThis. JSON (testmodels. getdepartmentbyschoolid (schoolid), jsonrequestbehavior. allowget );
}
These are basic things. You are welcome to give your comments. Thank you!