I tried to establish ajax request to asp.net mvc controller , but it give me internal server error
// My Products Controller
[HttpPost]
public ActionResult FilterCategeory(int prodID)
{
var categs = new Categ() {PROD_ID=prodID }.Search();
return Json(categs);
}
//My ajax request
$("#categs").empty();
var prm = $("#prods").val();
$.ajax({
type: "POST",
url: '@Url.Action("FilterCategeory", "Products")',
contentType: "application/json; charset=utf-8",
data: {prodID: prm },
dataType: "json",
success: function (data)
{
alert('Success');
},
error: function () { alert('error');}
});
The ajax request throws Invalid JSON primitive exception. So Pass the data using JSON.stringify(obj)
Ajax Request
var prm = $("#prods").val();
var obj = { prodID: prm };
$.ajax({
type: "POST",
url: '@Url.Action("FilterCategeory", "Home")',
contentType: "application/json; charset=utf-8",
data : JSON.stringify(obj),
dataType: "json",
success: function (data) {
alert('Success');
},
error: function () { alert('error'); }
});
Check this question hope it will help you.
You can check the error type in Firefox or Chrome In firefox
Right click the browser click Inspect Element . Then selected the Network tab. When you click the request it will show header, cookies etc. From that choose Response. So you can found the error
In chrome
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.