JavaScript How To Open File And Load Contents Into A Variable
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How To Open File And Load Contents Into A Variable

  1. #1
    Join Date
    Sep 2005
    Posts
    71

    How To Open File And Load Contents Into A Variable

    Hi,

    in my PHP webpage I specify 3 files, like:

    Code:
    $first_file = $_POST["one"];
    $second_file = $_POST["two"];
    $third_file = $_POST["three"];
    then I have a JS fuction, that in some points, needs to open each file and store the data of each file into a variable. My questions are 2:
    First, how do I save all data of each text file into a JS variable?
    Second, the part of the Js function which has these variables looks like this:

    Code:
                  series:
                    [
                        {
                            name: 'ONE',
                            color: 'blue',
                            data:
                            [
                                     HERE WE SHOULD PLACE ALL DATA FROM FILE 1                     
                            ]
                        },
    
                        {
                            name: 'TWO',
                            color: 'yellow',
                            data:
                            [
                                     HERE WE SHOULD PLACE ALL DATA FROM FILE 2                     
                            ]
                        },
    
                        {
                            name: 'THREE',
                            color: 'red',
                            data:
                            [
                                        HERE WE SHOULD PLACE ALL DATA FROM FILE 3            
                            ]
                        }
             ]
    Can you please help me, how I can put the data of each file into the correct place? I am new to JS and came across a helpful snipet of code, but I do not know how I can place my data inside the JS code so as to use them.

    Thanks a lot!

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,839

    Re: How To Open File And Load Contents Into A Variable

    Just echo the PHP content in the middle of the JavaScript.

    PHP Code:
    <script type="text/javascript">
    var jsVariable = "<?php echo $phpVariable?>";
    </script>
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center