Problem with PHP inside Javascript, to get your PHP in your Javascript to work, in the folder with the JavaScript, the .htaccess file should include:
<FilesMatch "^.*?api.*?$">
SetHandler php5-script
</FilesMatch>
In that above example, any file that includes the string "api" will be processed as PHP. Then in the JavaScript file itself, set the ContentType back to JavaScript:
<?php
// Sets the proper content type for javascript
header("Content-type: application/javascript");
?> Now you can use <php or ?> tags in the JavaScript