views:

36

answers:

1

Usually when building sites I add something like this

var config = {
    basePath: '<?php echo BASE_PATH; ?>'
}

Simply so with my static JavaScript files I can do AJAX requests like

var request = config.basePath + 'ajax/get-something';

Does WordPress have a similar variable available to its JavaScript files by default, assuming I add my own scripts at the bottom of all WordPress included stuff?

Thanks

+2  A: 

In the admin, there's a global variable ajaxurl that gives you the WP Ajax Url. I don't know if there's one for the front end built in, but you can do something like this to do it:

add_action( 'wp_head', create_function( '', '// echo your content here' ) );
John P Bloch