0

Where do I start debugging a jQuery/Javascript function, that calls an API on my server, when it works perfectly well locally - but when uploaded to the server, just returns an HTTP500 error?

I've tried fiddler, but it shows nothing in JSON/XML - the only thing it does show is in the Auth section:

Fiddler Image

The server Event Logs show nothing around the times I'm trying to test this.

Does the Fiddler response suggest anything is wrong, or can anyone sugget what I may need to turn on in the Event Viewer to capture whatever these 500 errors may be?

Thanks for any help,

Mark

Mark
  • 7,778
  • 24
  • 89
  • 147

2 Answers2

1

Try adding some console.log() messages which surround the javascript call and are within the callback functions. Doing so will let you know where the failure is occurring. When debugging javascript I typically stick to the Network tab within Chrome Developer Tools and Firebug. By using these tools you get proper output from your console.log() messages.

Specifically, in your jquery result handler I would add the following:

console.log(resultObject);

This will output the entire object tree so that you can drill down into the meat from within Firebug or Chrome Developer Tools... if you need to.

If, for whatever reason, you are opposed to littering your code with log messages then check to see that the call is actually happening when you are testing from your server. You should see whether or not javascript is sending the HTTP request by looking at your network traffic either in Fiddler or browser based tools. If the request is not happening then your code is breaking prior to the call which, in your case, probably means environmental differences.

Is everything referenced and configured properly? Check for null values due to improper configuration or bad references.

bradj
  • 890
  • 5
  • 11
1

500 is a "server error", which basically means something (could be almost anything) broke at the server side.

I would recommend:

  1. Investigate your options for exception handling: http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling
  2. Consider setting the IncludeErrorDetailPolicy to Always, though note that this is a setting that shouldn't be left in-use on a production environment - Error messages returned from Web API method are omitted in non-dev environment
  3. Examine server-side error logging. I'm a big fan of ELMAH. You'll need a little extra effort to get it working properly in Web API - http://blogs.msdn.com/b/webdev/archive/2012/11/16/capturing-unhandled-exceptions-in-asp-net-web-api-s-with-elmah.aspx
Community
  • 1
  • 1
Snixtor
  • 4,239
  • 2
  • 31
  • 54