View Full Version : including PHP generated array into .js file

03-20-2004, 02:28 PM
I am having php generate an array which needs to be accessed by a javascript function in a .js file.

I have tried including the following inside the .js file:

document.write("<SCR" + "IPT LANGUAGE='JavaScript1.2' SRC='New_Arrays4_2.js.php' TYPE='text/javascript'><\/SCR" + "IPT>");

but this doesn't seem to work.

I know the output of the php file is ok because when I paste its output into the .js file it works fine.

Thank you for any help.

03-20-2004, 04:04 PM
if your output cut & pasted works when accessed as in your script above then there is no reason that the method you are using should not work either.

with similar issues I have 9/10 found that its a simple formatting issue , e.g. the javascript produced by PHP being all on one line at which point a missing semi-colon is enough to throw an error..

use mozilla if you have it to see the actual javascript error

03-20-2004, 04:08 PM
but if I paste the output, wouldn't a formatting problem show up there as well?
thank you,

03-21-2004, 02:42 AM
yes , all I can say is that its normally something like the above whenever I have similar issues .. sometimes PHP called directly does not throw an error that is thrown when included elsewhere (if for example an include path was suddenly wrong when called as above) you won't see these generated errors but javascript will , it can hardly hurt to look!

03-21-2004, 02:05 PM
Your suggestion to use Mozilla was really helpful. I did find some errors. I still haven't got it to work, but I feel I will get there. Many thanks for looking at my problem.