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.