Is there a good way to get the debug information that Django provides when using jQuery to make Ajax calls? Right now when I make a call, I just see a http/200 server error in the python runserver window, but because the call is made through javascript, I don't get a debug page with all the information.
You can inspect the contents of the response returned to your jQuery ajax call. Using a tool like Firebug can make this pretty easy.
Django will still return the debug page, it's just that it is responding to the ajax call rather than a regular browser request.
It's often a good technique to get your stuff working with regular requests, and then "ajaxify" them only once you are sure the server side code is working.
You can use this snippet: http://www.djangosnippets.org/snippets/650/ to get plaintext tracebacks for viewing in firebug, instead of HTML.
When you receive an AJAX error like that, you can replace your current document contents with the debug/error document returned from the server. For example, you can do something like the following:
$.ajax({
url: 'failing_controller/',
type: 'POST'
})
.fail(function (jqXHR, textStatus, errorThrown) {
document.open();
document.write(jqXHR.responseText);
document.close();
})
.success(function (data, textStatus, jqXHR) {
// ... handle data ...
});
This can be really helpful during development and debugging, because it lets you inspect the server state in real-time. You will probably want to replace the failure handler with something more proper in a production environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With