Array data taken from external files

D

Doggie

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?
 
J

Jonas Raoni

Doggie said:
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 ;]
 
D

Doggie

Jonas said:
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 :)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top