Simple AJAX callback
Disclaimer: I've never done this with Drupal 6.

You want to use a menu callback: You create a menu item (which is just a path associated to a PHP function), and point your query request at that path.