views:

2601

answers:

5

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?

Thanks!

$.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'}

+1  A: 

You can look up HTTP status codes here, this error is telling you:

"The server encountered an unexpected condition which prevented it from fulfilling the request."

You need to debug your server.

Tom
+3  A: 

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.

tvanfosson
Your first sentence is misleading (implying the 500 error is occuring client-side). I nearly downvoted you for it before I read the answer more thoroughly. You might want to clarify a bit.
Macha
Thanks. Updated.
tvanfosson
http://www.fiddler2.com/ is also very useful to view the actual response from the server.
Glen Little
A: 

There should be an event logged in the EventVwr (Warning from asp.net), which could provide you more details on where the error could be.

Ramesh
A: 

A 500 from ASP.NET probably means an unhandled exception was thrown at some point when serving the request.

I suggest you attach a debugger to the web server process (assuming you have access).

One strange thing: You make a POST request to the server, but you do not pass any data (everything is in the query string). Perhaps it should be a GET request instead?

You should also double check that the URL is correct.

codeape
Right.. I was using a GET originally but I get the same error.
Nick
Have you tried doing the request from the browsers address bar? Do you get a 500 status then as well?
codeape
And double check that the URL is correct.
codeape
A: 

Can you post the signature of your method that is supposed to accept this post?

Additionally I get the same error message, possibly for a different reason. My YSOD talked about the dictionary not containing a value for the non-nullable value. The way I got the YSOD information was to put a breakpoint in the $.ajax function that handled an error return as follows:

<script type="text/javascript" language="javascript">
function SubmitAjax(url, message, successFunc, errorFunc) {
    $.ajax({
        type:'POST',
        url:url,
        data:message,
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success:successFunc,
        error:errorFunc
        });

};

Then my errorFunc javascript is like this:

function(request, textStatus, errorThrown) {
        $("#install").text("Error doing auto-installer search, proceed with ticket submission\n"
        +request.statusText); }

Using IE I went to view menu -> script debugger -> break at next statement. Then went to trigger the code that would launch my post. This usually took me somewhere deep inside jQuery's library instead of where I wanted, because the select drop down opening triggered jQuery. So I hit StepOver, then the actual next line also would break, which was where I wanted to be. Then VS goes into client side(dynamic) mode for that page, and I put in a break on the $("#install") line so I could see (using mouse over debugging) what was in request, textStatus, errorThrown. request. In request.ResponseText there was an html message where I saw:

<title>The parameters dictionary contains a null entry for parameter 'appId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ContentResult CheckForInstaller(Int32)' in 'HLIT_TicketingMVC.Controllers.TicketController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.<br>Parameter name: parameters</title>

so check all that, and post your controller method signature in case that's part of the issue

Maslow