用PHP常量重构jQuery

This is a clarification and advice question. From building an application I have come to refactor much of my jQuery from the <head> tags into its own .js files. My contention is that I'm using constants to define paths.

Therefore if I refactor code that needs those PHP constants then the jQuery code will not work, because as far as I know I cannot include the init.php file that contains the constants. Am I mistaken? is there a way to include the needed Constants within my jQuery files for code such as the type below:

$.ajax({
    type: "POST",
    url: "<?php echo SITE_PATH; ?>file.php"
});

The above code is a snippet from a jQuery AJAX POST, which works fine within my head. But if I was to refactor the code to its own JS file how would I go about getting access to the desired constants and using them within JS?

Any thoughts would be appreciated.

Just pass the routes through your object params. I would suggest the following, it gets more organized and it is also easier to use Closure Compiler or other tools that affect the JS later.

on a .js file:

function myObj(obj){
   var routes = (obj && obj.routes) || {};

   $.ajax({
    type: "POST",
    url: routes.file
   });
}

on your html:

myObj({ routes: { file: "<?php echo SITE_PATH; ?>file.php" } });