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?