Reputation: 135
I have been stuck at this for some time now. I am trying to send a bool from my controller to the view through ajax. I tried several different tutorials and methods but can't seem to be able to retrieve some simple data. I was hoping somebody can explain what am I doing wrong.
Here is my code:
Ajax:
$(document).ready(function () {
$.ajax({
"url": "/social/checkfollow",
"type": "GET",
"dataType": "json",
"success":function(data) {
console.log(data);
},
"error": function(data) {
console.log(data.status +" "+ data.statusText);
}
});
});
And the controller:
[HttpGet]
public virtual ActionResult CheckFollow()
{
var pass = false;
return Json(new {result = pass});
}
For some reason i keep getting 500 Internal Service error. i know it's a really basic question and i would really appreciate your help.
Upvotes: 2
Views: 1611
Reputation: 154
Return statement not properly for pass json so i have add sample code so try it and let me know any problem.
[HttpGet]
public virtual ActionResult CheckFollow()
{
var pass = false;
return Json(new {result = pass}, JsonRequestBehavior.AllowGet);
}
Upvotes: 2
Reputation: 941
Your return statement probably should be:
return Json(new {result = pass}, JsonRequestBehavior.AllowGet);
Pertinent explanation of the AllowGet: Why is JsonRequestBehavior needed?
Upvotes: 6