Calling a php file from a javascript file in wordpress
If you want to able to use the WordPress functions the your ajax call should be to the wp-admin/admin-ajax.php and you should use wp_ajax hook, take a look at What’s the preferred method of writing AJAX-enabled plugins? I posted a nice example of how to do that there.