How would one dynamically load Javascript that has been parsed as PHP? -


I'm trying to load javascript dynamically, which is parsed as PHP so that I can convert javascript to Can pass the PHP variable, and then load this file into the primary PHP document. I have a document called myscript.js.php that includes JavaScript and PHP. I tried to use it in the primary document, such as jQuery's Hoscript:

  $ GetScript ("myscript.js.php", function () {warning ('load script.');});   

This attempt failed - I'm assuming the file due to the .php extension. Is PHP anyway to load javascript anyway? I have some session variables which I am going through JavaScript that will be updated frequently, creating the need to reload Javascript.

Your piece of code looks correct syntax. Did you check the status of the AJAX call? You must set a header in the PHP page, such as

  header ('content-type: text / javascript; charset = UTF-8');   

Otherwise jquery will throw an error because its a return script file is expected and the header is not in accordance with it.

Look at it ..

Comments