Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

152
Views
AJAX and c# mvc controller get bool

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.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Your return statement probably should be:

return Json(new {result = pass}, JsonRequestBehavior.AllowGet);

Pertinent explanation of the AllowGet: Why is JsonRequestBehavior needed?

about 4 years ago · Santiago Trujillo Report

0

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);
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!