Jumat, 18 Maret 2011

Debug ajax requests in more easy way

Jumat, 18 Maret 2011

When I have to debug ajax requests, I always feel pain in the ass accessing the exception message and backtrace. It require at least 3 clicks to get them and only in the plain html format, that web framework use to generate. Is it better to see it at once in the browser popup?

This can be done with Ajax callbacks offered by javascript framework(if yours doesn't - get rid of it). We can catch errors there and display popup. JQuery example with #ajaxError callback that fires on every unsuccessful ajax call:

(function() {
var popup = null;
$(document).ajaxError(function(event, xhr, settings, exception) {
if (popup) {
popup = null;
popup = window.open(null, "error", "width=800,height=600");
return true;

Checked in FF and Chrome(IE is not a browser).
Screenshot with the result. Be aware of browser popup blocker.
You always have a control when popup the error. I like it to be "in any case". But You can customize it with xhr.status and if statement on the server side.

In some cases it might be useful not only in the development but in production as well. But it should be an iframe inside of pretty html layout, so that designers won't blame programmers too much.

Related Posts :

1 komentar:

Leonid Shevtsov mengatakan...

I'd just like to add that Firebug itself can render an AJAX HTML response.

Posting Komentar

Related Posts Plugin for WordPress, Blogger...




BACA BERITA is proudly powered by Blogger.com | Template by Blog Zone