Array data taken from external files

Discussion in 'Javascript' started by Doggie, Feb 22, 2006.

  1. Doggie

    Doggie Guest

    Hi,

    I am working on JS navigation for my web page. Contents of 3 subpages
    are located in the array as shown below. When certain key is pressed on
    the page, div is filled with data taken from one of the array rows.

    ***

    var content=new Array()
    content[1]='<p>some text</p>'
    content[2]='<p>some other text</p>'
    content[3]='<p>yet another text</p>'

    ***

    The question is: is it possible in some simple way to put the data from
    those 3 rows into 3 separate files and make the JS code to take the data
    from those files? (I want to have 3 files with plain HTML) If so, please
    show me some example how to do that. Or give me some address where I can
    read about it, please. I have been using Google for several hours -
    unfortunately without any luck.

    In general - here is what I would like to do:

    ***

    var content=new Array()
    content[1]=[contents of '1.html' file]
    content[2]=[contents of '2.html' file]
    content[3]=[contents of '3.html' file]

    ***

    How can I put the above into JS code?

    --
    Best wishes,
    Doggie
     
    Doggie, Feb 22, 2006
    #1
    1. Advertising

  2. Doggie

    Jonas Raoni Guest

    Doggie wrote:
    > The question is: is it possible in some simple way to put the data from
    > those 3 rows into 3 separate files and make the JS code to take the data
    > from those files? (I want to have 3 files with plain HTML)
    >
    > var content=new Array()
    > content[1]=[contents of '1.html' file]
    > content[2]=[contents of '2.html' file]
    > content[3]=[contents of '3.html' file]


    You don't have file access through JavaScript. But you can load data
    from files *stored on the same host* by using a hidden iframe/frame or
    that XMLHttpRequest object.

    But since it's a menu you should do things in a very different way, you
    can't make your site JavaScript dependent.

    1. Output the menu as pure html.

    <ul>
    <li>
    Menu A
    <ul>
    <li>Submenu 1</li>
    <li>Submenu 2</li>
    </ul>
    </li>
    <li>Menu B</li>
    </ul>

    2. Using JavaScript parse the structure, build your "cute" menu and
    remove the old nodes.

    That's the right way ;]


    --
    Jonas Raoni Soares Silva
    http://www.jsfromhell.com
     
    Jonas Raoni, Feb 22, 2006
    #2
    1. Advertising

  3. Doggie

    Doggie Guest

    Jonas Raoni wrote:
    > You don't have file access through JavaScript. But you can load data
    > from files *stored on the same host* by using a hidden iframe/frame or
    > that XMLHttpRequest object.
    >
    > But since it's a menu you should do things in a very different way, you
    > can't make your site JavaScript dependent.

    (...)

    OK. Thanks for the help :)

    --
    Best wishes,
    Doggie
     
    Doggie, Feb 23, 2006
    #3
  4. Doggie

    Jonas Raoni Guest

    Doggie wrote:
    > Jonas Raoni wrote:
    >> You don't have file access through JavaScript. But you can load data
    >> from files *stored on the same host* by using a hidden iframe/frame or
    >> that XMLHttpRequest object.
    >> But since it's a menu you should do things in a very different way,
    >> you can't make your site JavaScript dependent.

    >
    > (...)
    >
    > OK. Thanks for the help :)


    Nevermind, good luck and god bless the polish girls haha \o/


    --
    Jonas Raoni Soares Silva
    http://www.jsfromhell.com
     
    Jonas Raoni, Feb 23, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. System Attendant
    Replies:
    0
    Views:
    269
    System Attendant
    Jun 10, 2004
  2. System Attendant
    Replies:
    0
    Views:
    266
    System Attendant
    Jun 10, 2004
  3. System Attendant
    Replies:
    0
    Views:
    301
    System Attendant
    Jun 10, 2004
  4. System Attendant
    Replies:
    0
    Views:
    316
    System Attendant
    Jun 10, 2004
  5. System Attendant
    Replies:
    0
    Views:
    259
    System Attendant
    Jun 13, 2004
Loading...

Share This Page