I am looking to dynamically load javascript that has been parsed as PHP so that I will be able to pass PHP variables to javascript, and then load this file into the primary PHP document. I have a document called myscript.js.php that includes the javascript and PHP. I attempted to load it into the primary document using jQuery’s getScript like this:
$.getScript("myscript.js.php", function() {
alert('loaded script.');
});
This attempt failed – I am assuming because of the .php extension on the file. Is there anyway to dynamically load javascript that includes PHP? I have a few session variables that I am looking to pass through javascript that will be updated frequently, creating a need for the javascript to be reloaded.
your piece of code looks syntactically correct. Did you check the status of the ajax call?
you will have to set a header in the php page returned as,
since otherwise jquery will throw an error since its expecting a script file to be returned and the header does not match it.
look at this.. http://api.jquery.com/jQuery.getScript/#comment-104973932