The following JSON call always hits the AJAX error handler, and I can’t figure out why:
$.ajax({
type: "GET",
url: '<%= Url.Action("MyTest", "Detail") %>',
dataType: "json",
error: function (xhr, status, error) {
alert(xhr + " | " + status + " | " + error);
},
success: function (json) {
alert(json);
}
});
All I get is Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://localhost:4497/Detail/MyTest?_=1320681138394
When I set a breakpoint in the controller, I can see that it’s being reached, so I’m not sure where the request is falling down. Here’s the action in the DetailController:
Function MyTest() As JsonResult
Return Json("Hello")
End Function
Any ideas?
The jQuery error handler is fired because it failed to parse the returned page as valid JSON. Since you get 500 internal server error, the page most likely doesn’t contain valid JSON.
Load this page in your browser and fix it until it gives valid json:
After it is giving valid json in the browser, try the jQuery ajax call.
I have no idea of even the basic functionality of VB.NET but can you make so that the only thing that is printed on http://localhost:4497/Detail/MyTest is like:
If the only thing the page is outputting is
{"message":"hello"}then json error handler will not fire