Does WordPress expose a base URL in its JavaScript by default?
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
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' ) );
精彩评论