Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging jQuery ajax 500 Internal server error

Tags:

jquery

ajax

My working CodeIgniter site is giving a 500 Internal Server Error while hosting it on MediaTemple. It is happening during a jQuery Ajax call.

I have no idea what could have gone wrong. Is the error from the controller or the model? My Ajax call:

$.ajax({
    url: "<?php echo site_url('invites/save_email') ?>",
    type: 'POST',
    data: form_data,
    success: function(msg) {
    window.location.href = "<?php echo site_url('invites/moreinvites')?>"
        return true;
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
        alert(xhr.responseText);
    }
});

xhr.responseText has returned me <p>The action you have requested is not allowed.</p>. But what does that mean?

like image 262
Himanshu Yadav Avatar asked Mar 08 '13 00:03

Himanshu Yadav


People also ask

How do I fix a 500 Internal server error?

Clear your browser cache and cookies Check these articles on deleting the cache on an Android phone or iPhone, if you use a mobile device. Alternatively, you can test opening the page from another browser. For instance, if you use Chrome, try Firefox or vice versa.

What is 500 Internal server error AJAX?

The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client.


1 Answers

You can try using alert(xhr.responseText); or console.log(xhr.responseText); (the later will show up in your browser console e.g. firebug) in your error callback, doing so you can get the message associated with the exception (if any).

error: function (xhr, ajaxOptions, thrownError) {
           alert(xhr.status);
           alert(xhr.responseText);
           alert(thrownError);
       }

or

error: function (xhr, ajaxOptions, thrownError) {
           console.log(xhr.status);
           console.log(xhr.responseText);
           console.log(thrownError);
       }
like image 69
Snivs Avatar answered Sep 20 '22 20:09

Snivs