tags:

views:

289

answers:

7

Hi,

I am getting "500 Internal Server Error" when I used ajax call. What is causing this problem? How to resolve it?

A: 

If your server is running Windows, then look in the event log and see what server error occurred.

John Saunders
or the IIS logs
Kane
A: 

Look in the server log, which on Linux is normally in something like /var/log/apache2 or /var/log/httpd.

Download Firebug, intercept the ajax call and load it in the browser or look at its output. Make sure you server is set to report errors (look at php.ini for PHP settings, for example). Whatever is causing it is probably going to show up.

Make sure you don't actually throw the error 500 yourself in the code.

If you use PHP, then use a debugger, such as PHPEd or xdebug and step through the code. That's the way I debug my PHP and it's the best way, though takes some time to set up.

Artem Russakovskii
+3  A: 

debugging, fixing, and resolving a server error from an Ajax call is exactly the same process as any other request.

  1. Check the web server error logs for any indications of what the error is

  2. Introduce debug statements into the serverside code around where the error is occuring (and add a little bit to your ajax request to dump all the response as plain text)

It may also be useful to copy the URL and querystring used in the Ajax call and paste it into your browser to view any responses.

Firebug for Firefox is also a useful diagnostic tool for testing what is being sent as part of the Ajax call and what is being sent back as a response.

HorusKol
A: 

You created and fired off a request to a server with whatever you did in Ajax. So far, so good. The server tried to process your request but ran into an error condition. That's usually caused by some bug in the server code.

As John Saunders advises, you can usually get more information on the server-side problem by looking into its logs.

Carl Smotricz
A: 

You should first debug your ajax request; here is how to do so:

http://sarfraznawaz.wordpress.com/2009/09/11/debugging-ajax-requests/
Sarfraz
+1  A: 

Use fiddler or firebug to look at your network request/response.

It looks like you may be using perl? Try adding use CGI::Carp qw(fatalsToBrowser); on a new line after your path to perl declaration.

row1
Specifically at the response to the request that fails, it is possible that the server will return some information about the failure. Otherwise, you have to look at the server side logs.
John Paulett
@John, correct I have clarified it.
row1
A: 

My step usually (in particular order):

  1. open firebug and look up the particular ajax request from console. Then, see the parameter, header, and URL request. Examine each data to see what goes wrong. If it all seems OK
  2. I will look at my server log (httpd-error.log on Apache) and check any particular error that came from that request.
  3. Fix what is wrong based on all there checking.
silent