When jQuery Ajax requests data, the type cannot use GET, jqueryajax

Source: Internet
Author: User

When jQuery Ajax requests data, the type cannot use GET, jqueryajax

Write an ASP. net mvc example that uses jQuery's $. Ajax to call controller data.

 

 

Create a view:

 

Running result:

 

Everything works, but in this example we only GET the data and do not POST any data to the Controller. We try to change the type of jQuery code to GET.

 

Browsing again, but the results did not reach our expectation, and no data is displayed.

 

Strange: after checking the information, when the original JsonResult operation returns JSON, JsonRequestBehavior is POST by default. Therefore, we need to specify the parameter option JsonRequestBehavior. AllowGet:

 

After this parameter option is added, the display result is the same as that of POST.

Of course, for some reason, if your JsonResult can only use POST, you can use another parameter JsonRequestBehavior. DenyGet:

 

After explicitly specifying DenyGet, $. Ajax of jQuery cannot use GET.

Related Article

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.