JQuery Ajax Post results in 500 Internal Server Error

Nick picture Nick · Aug 28, 2009 · Viewed 570.9k times · Source

I am trying to perform this AJAX post but for some reason I am getting a server 500 error. I can see it hit break points in the controller. So the problem seems to be on the callback. Anyone?

$.ajax({
    type: "POST",
    url: "InlineNotes/Note.ashx?id=" + noteid,
    data: "{}",
    dataType: "json",

    success: function(data) {
        alert(data[1]);
    },
    error: function(data){
        alert("fail");
    }
});

This is the string that should be returned:

{status:'200', text: 'Something'}

Answer

tvanfosson picture tvanfosson · Aug 28, 2009

I suspect that the server method is throwing an exception after it passes your breakpoint. Use Firefox/Firebug or the IE8 developer tools to look at the actual response you are getting from the server. If there has been an exception you'll get the YSOD html, which should help you figure out where to look.

One more thing -- your data property should be {} not "{}", the former is an empty object while the latter is a string that is invalid as a query parameter. Better yet, just leave it out if you aren't passing any data.