How to process javascript file on server?

  • danmerrino
  • Novice
  • Novice
  • danmerrino
  • Posts: 21

Post 3+ Months Ago

Hello helpful lads!

i come before you with a problem again...here is what want to do:

i have a .js file which contains all the javascript for a page. This .js file needs a lot of data, which is "stored" in some variables in a php script.

i would like to insert all these variables into the javascript code before the server serves the file to the client, perhaps by building the .js file on the server.

i tried this by calling it file.php instead of file.js and storing all the javascript code in a php string of type heredoc and then printing it with echo like so:
Code: [ Select ]
<?php
Header("content-type: application/x-javascript");
echo <<<"EOD"
javascript here
EOD;
?>
  1. <?php
  2. Header("content-type: application/x-javascript");
  3. echo <<<"EOD"
  4. javascript here
  5. EOD;
  6. ?>


At the top i also set:

and i linked this php file to my page as a javascript file.

But i get a parsing error.

does anybody know how i can accomplish this?

or is there any other way to insert Data into javascript code before it is used?
(I would like to avoid accessing the php script in any way with javascript to read the data.)

I hope somebody can help,

greetings,
dan
Moderator Remark: Added [code] tags
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • danmerrino
  • Novice
  • Novice
  • danmerrino
  • Posts: 21

Post 3+ Months Ago

NEVER MIND, SITUATION RESOLVED!

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 57 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.