Himanshu Yadav Himanshu Yadav - 4 months ago 55
jQuery Question

Debugging jQuery ajax 500 Internal server error

My working codeigniter site is giving 500 Internal Server Error while hosting it on MediaTemple. It is happening during an jquery ajax call.

But I have no idea what could have gone wrong.Is the error from controller or model? There is nothing I don't know how to debug it.
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 it mean.

Answer

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);
       }
Comments