0

So, I have been using $.getJson() successfully to grab data. In this instance, I needed to synchronously grab data from the server, so I used:

$.ajax({
    type: "GET",
    async: false,
    url: "/Mapping/MappingExists?id=" + id,
    dataType: "json",
    success: function (data) {
        alert("SUCCESS");
        EnableAll("disableElement");
    },
    error: function () {
        alert("ERROR");
        result = true;
    }
});

The controller is:

[HttpGet]
    public JsonResult MappingExists(int id)
    {
        if (Privileges.HasAccess(User.Identity.Name))
        {
            try
            {
                var map = new Mapping
                {
                    ID = id
                };
                return this.Json("{\"MappingExists\": \"" + map.Exists() + "\"}", JsonRequestBehavior.AllowGet);
            }
            catch (Exception x)
            {
                return this.Json("{\"Message\": \"Unable to Get Mapping.\"}");
            }
        }
        return null;
    }

I put a break point in the very first line of the controller, but it does not get hit. I get a 500 error in the JS console. I think the error is thrown because the Response Headers return text/html; charset=utf-8 while the Request Headers are expecting application/json, text/javascript, /; q=0.01.

This was working at one point, then all of a sudden it started throwing the 500 error. Any ideas on how to resolve this?

ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
  • What is the repose body from the server? This could be related to an actual server-side error. – DanC Mar 14 '13 at 19:52
  • It is a server side issue. Going directly to the url showed the error was caused from one of the values in the dropdown being sent to the controller was a string and the controller was expecting an integer. *face-palm* – ScubaSteve Mar 14 '13 at 20:02
  • your post confuses me. on the one hand the title implies you're getting wrong data back on the other hand your body implies the action method never gets hit. – Dave Alperovich Mar 14 '13 at 20:46
  • Yeah, the action was never getting hit. I'm not sure why it was telling me that the response header is returning something. I think it was returning html because it was returning an error. – ScubaSteve Mar 15 '13 at 01:24

0 Answers0