I feel that the above title isn't very well worded since I can't figure how to state it properly using few words. Anyway, what I'd like to do is this:
$.post("foo.php", data, function(msg) {
//the js part is easy enough to handle
});
This is simple enough but how do I get foo.php to use Drupal 7's functions? While it would probably make my life much easier to use ordinary php code to do all my database queries, I'd like to stick with Drupal functions to play it safe.