469,276 Members | 1,674 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

Javascript Reload external Files

I am very new using javascript and I faced a problem that with my expertise I cannot solve.
I wrote a small html file that handle a vertical menu. I wrote a function to show the menu correctly using javascript. The contents of the menu are dynamic changed. In my project I have two javascript file: the first has all the functions to handle the menu and the second has just a JSON array with the information for the menu.
Expand|Select|Wrap|Line Numbers
  1. var mv =
  2. [
  3. ["1","Fórum"],
  4. ["11","Aberto","http://labadm.metodista.br/MP.exe/mp?si=49179&w=3&p1=1&p2=172"],
  5. ["12","Pessoal","http://labadm.metodista.br/MP.exe/mp?si=49179&w=3&p1=1&p2=173"],
  6. ["2","Consulta"],
  7. ["21","Enviar E-mail","mailto:monocomltd.1305@macpenn.com.br"],
  8. ["3","Caso"],
  9. ["4","Sair do experimento"]
  10. ];
(the language here is Portuguese)

I load the two js files in my html in the static way (the first with the functions and the second with the data):
<script type="text/javascript" src="ms_js/mp_mm.js"></script>
<script type="text/javascript" src="ms_js/mp_mm_d.js"></script>
I also run the menu function in the body section:
[HTML]<body onload="menu(mv,0),menu(mh,1)">[/HTML]

I wanted to change the menu information dynamically changing only the js data file as the user click in a link (this is a test project only), instead of running all page again, for this action I am using two function I could found here http://www.javascriptkit.com/javatut...criptcss.shtml.

The main function use parentNode.replaceChild to replace the mp_mm_d.js file (that has only a JSON var inside) when the user click the link:

[HTML]<a href="javascript:replacejscssfile('ms_js/mp_mm_d.js', 'ms_js/mp_mm_d1.js', 'js')">Troca Menu</a>
To run the menu function I include in the main function above a call to my menu constructor: menu(mv,0)

The mp_mm_d1.js is identical the older file mp_mm_d.js the the var mv contents (the name of the variable is the same but the contents).

Everything works fine, I mean: the mp_mm_d.js file was replaced by mp_mm_d1.js file and I got any error in the process, but the variable contents include in the mp_mm_d1.js was not loaded or not changed in the process.
I tried a lot of things to make this running well without success.
It seems that the browser do not reload the replaced file changing the variable as requested, or I am misunderstanding the whole process.
Is there a way to reload the js file in order to use the new variable information?

Thank you for reading this and hope to get an answer soon.

Nov 25 '07 #1
3 2785
16,027 Expert Mod 8TB
Welcome to TSDN!

Have you inspected the DOM after replacing that it has indeed been replaced?
Nov 26 '07 #2
Dear friends, I had already solved the problem! The key was to check the complete reload before continuing the process. Thanks all!
Nov 27 '07 #3
16,027 Expert Mod 8TB
Glad you got it working. Post again if you have another question.
Nov 27 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by annon | last post: by
5 posts views Thread by joaopedrogoncalves | last post: by
2 posts views Thread by robert.waters | last post: by
3 posts views Thread by I.g.o.r. | last post: by
4 posts views Thread by James Pemberton | last post: by
4 posts views Thread by Neo Geshel | last post: by
7 posts views Thread by Hrvoje Vencl | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.