Aquarionics

Tuesday 6th March 2007

Debugging Ajax

One of the problems with Ajax is that the server side of it becomes invisible. You send a request to the server with an ajax request object, and you can get output from the JS by firebug, or alert boxes, or whatever, but for the script running on the other side, there's no visible place for the output.

There are many ways around it, but my current favourite is Growl.

Growl is a notification system for OS X, where programs send messages to the central demon, and it pops up a little dialog message that eventually fades away. They're nice for debug, so I have this:


<?PHP
require_once 'Net/Growl.php';

$growl =& Net_Growl::singleton('Net_Growl'array('Messages'), '[Password]');
$growl->_options['host'] = '[MyIP]';

$GLOBALS['growl'] = $growl;

function debug($message){
    $backtrace = debug_backtrace();
    
    array_shift($backtrace);
    
    if (is_array($message) || is_object($message)){
        $message = print_r($message,1);
    }
    
    $title = sprintf("Debug - %s - %d"$backtrace[0]['function'], $backtrace[0]['line']);
    

    $GLOBALS['growl']->notify('Messages'$title$message);
}




With network notification enabled on Growl on my local machine, I get a little debug message without interrupting the application flow. Of course, I could use log files, but that wouldn't be quite as pretty.

Those who spoke on this:

gravatar image

Tom Allender:

2007-03-09 11:38 3 days after the Original Article

I think it sounds very clever and suitably OSX-fluffy.

Comment Link Reply to Tom Allender


Nicholas 'Aquarion' Avenell is a web developer in London, you can find out more about him or how to get in touch.

There are more Articles, Projects, Journal Entries, Photographs and things that defy description here, too.

If you're looking for something specific, there are Calendar & Category -based lists of everything.

And if you want to follow stuff that appears here, try a Syndication Feed, or the generic Feed of everything.


Aquarion's last Twitter was: [updating]
Twitter last updated


More Articles:

[RSS Icon]
[ESF Icon]
[CDF Icon]

That which is relevant:


Explain Ads
© 2000 to 2008 inclusive Nicholas Avenell
All comments are the property of their creators, published with permission
(Unless otherwise indicated, the opinions and sentiments expressed on this site are those of the author and not of any organisation of which he is an affiliate, including his employer. Caveat Lector, E&OE. sigh)
0.180 seconds, 10 queries, 2.64Mb on Sun, 22 Jun 2008 18:28:42 +0000
Generated by Epistula Version 2.0.3