Tips for Debugging Ajax Applications - Part1

Debugging your Ajax applications can be quite challenging because:
  • There are so many technologies involved(PHP, MySQL, Javascript, DOM, and HTML).
  • You may be less familiar with Javascript and DOM.
  • Much of what happens goes on behind the scenes.
  • Because of the Javascript, you really need to test your applications on multiple browsers and platforms to ensure universal reliability.
In my experience developing Ajax applications from scratch, I've picked up quite a few useful debugging techniques, outlined in the following steps.

1. Run your applications through a URL!

For the PHP to work, it must be accessed through http://. This means that you must load your HTML page through http://.

2. Test your PHP scripts separately.

Be in the habit of doing this automatically, not just when things go awry.

3. Test your database queries separately.

Print out the exact query(ies) and use another interface, like the mysql client or phpMyAdmin, to confirm the results.

4. Validate, if appropriate, the data returned by the PHP script.

If the JavaScript function handling the returned data expects to receive XML or JSON, then the returned text must be in strict XML or JSON format.

5. Use Javascript alerts to indicate what's going on.

Since so much is going on behind the scenes, it's often necessary to shed some light on the process.Add code like alert('in the check_user() function'); to your Javascript code.

Additional tips for debugging ajax applications will be covered in part 2.