Getting jsonString via Jquery coming up empty

Posted by NoobCoder on Stack Overflow See other posts from Stack Overflow or by NoobCoder
Published on 2012-06-11T16:36:38Z Indexed on 2012/06/11 16:40 UTC
Read the original article Hit count: 148

Filed under:
|
|
|

I'm using asp mvc and I'm getting data in one part of my program like this

 public List<IncidentPerAreaCount> getIncident()
    {
        int RondeboschCounter = 0;
        int ClaremontCounter = 0;
        int AthloneCounter = 0;
        List<IncidentPerAreaCount> IncidentAreaCount = new List<IncidentPerAreaCount>();
        IncidentPerAreaCount Rondebosch = new IncidentPerAreaCount();
        IncidentPerAreaCount Claremont = new IncidentPerAreaCount();
        IncidentPerAreaCount Athlone = new IncidentPerAreaCount();

        List<Report> Reports = GetReports();
        for (int i = 0; i < Reports.Count(); i++)
        {
            if (Reports.AsEnumerable().ElementAt(i).Area == "Rondebosch")
            {
                RondeboschCounter++;
            }
            else if (Reports.AsEnumerable().ElementAt(i).Area == "Claremont")
            {
                ClaremontCounter++;
            }
            else if (Reports.AsEnumerable().ElementAt(i).Area == "Athlone")
            {
                AthloneCounter++;
            }

        }
        Rondebosch.AreaName = "Rondebosch";
        Rondebosch.NumberOfIncidents = RondeboschCounter;
        Claremont.AreaName = "Claremont";
        Claremont.NumberOfIncidents = ClaremontCounter;
        Athlone.AreaName = "Athlone";
        Athlone.NumberOfIncidents = AthloneCounter;

        IncidentAreaCount.Add(Rondebosch);
        IncidentAreaCount.Add(Claremont);
        IncidentAreaCount.Add(Athlone);

        return IncidentAreaCount;
    }

Then I'm trying to get this string via Jquery

 var Reports = [];
    $.ajax({
    url: "Home/getIncident",
    async: false,
    dataType: 'json',
    success: function (json) { Reports = json.whatever; }
    });
    alert(Reports);

However the alert function keeps coming up empty (ie empty textbox) instead of having a json formatted string with data.

Please help...

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JSON