. Net mvc3 2: Example of receiving JSON data asynchronously at the foreground (2)

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

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.