Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    including PHP generated array into .js file

    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.
    Patty

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    but if I paste the output, wouldn't a formatting problem show up there as well?
    thank you,
    patty

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,106
    Thanks
    11
    Thanked 101 Times in 99 Posts
    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!
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #5
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.
    Patty


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •