Ok, so for some reason, my ajax call keeps failing even though the server is returning 200 with valid json. Here is the ajax call:
$.ajax(
{
cache: false,
type: "GET",
url: "http://localhost:10590/api/entry",
dataType: "application/json; charset=utf-8",
success: function (result) {
alert('HIT');
},
error: function (request, type, errorThrown) {
alert('Fail' + type + ':' + errorThrown);
}
});
The error function is displaying blanks. Type says “error” but nothing after that. I’m trying to figure out why this would be happening???
Verified via fiddler, this is the json string that is being returned from the server:
{
"EntryId":0,
"EntryDate":"2012-12-14T18:10:48.2275967-07:00",
"BodyWeight":207.00,
"Bmi":0.0,
"Fat":0.0,
"Visceral":0.0,
"MuscleMass":0.0
}
http://jsonlint.com/ agrees that this is valid json.
UPDATE:
adding the following before the ajax call gets it to work in IE but not chrome:
$.support.cors = true;
The solution I ended up using was to request ‘jsonp’ from the server. In order to get my server to return jsonp, I had to create a custom formatter. i had a hard time finding a formatter for it since every post referred to Thinktecture, which wouldn’t compile for me. So here is what I ended up with: