By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Javascript Reload external Files

P: 2
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.
Example:
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. ];
  11.  
(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):
[HTML]<head>
.
.
.
<script type="text/javascript" src="ms_js/mp_mm.js"></script>
<script type="text/javascript" src="ms_js/mp_mm_d.js"></script>
</head>
[/HTML]
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>
[/HTML]
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.

Wagner
Nov 25 '07 #1
Share this Question
Share on Google+
3 Replies


acoder
Expert Mod 15k+
P: 16,027
Welcome to TSDN!

Have you inspected the DOM after replacing that it has indeed been replaced?
Nov 26 '07 #2

P: 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

acoder
Expert Mod 15k+
P: 16,027
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.