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

How to upload an updated file in javascript

P: 58
Hi,
Suppose i have a notepad file having some contents. i saved it as test.js.(Having th e content Hello) and i used this .js in another .js file. Later if i am updating the contents in test.js file as hi. will it show the changes in test.js pls reply
Nov 27 '08 #1
Share this Question
Share on Google+
12 Replies


P: 58
Hi,
Suppose i have one .js file.

one .txt file is included in the .js file. Later if i am making the changes in .txt file will it change automatically. How? any code.......Pls help me fast.Its very urgent.
Nov 27 '08 #2

gits
Expert Mod 5K+
P: 5,390
please don't double post your question ... read the Posting Guidelines before posting.

kind regards
MOD
Nov 27 '08 #3

gits
Expert Mod 5K+
P: 5,390
How did you include a txt-file in a JS-file? could you please post what you have done so far, because its quite hard to understand what you mean ... and may be havin a look at the code clears that up a bit?

kind regards
gits
Nov 27 '08 #4

P: 58
Hi thanks for reply. My test.js is as follows

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script type="javascript/text" src="first.txt">
  4. document.write("Hi");
  5. </script>
  6. </body>
  7. </html>
  8.  
Is it possible to include like src="first.txt". If after some time i make changes to this text file will it be able to view the changes when i am executing test.js
Nov 27 '08 #5

gits
Expert Mod 5K+
P: 5,390
it should look like this:

html-file:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script type="text/javascript" src="first.js"></script>
  4. </body>
  5. </html>
  6.  
js-file - 'first.js':

Expand|Select|Wrap|Line Numbers
  1. document.write('foo');
  2.  
kind regards
Nov 27 '08 #6

P: 58
Hi, Thanks for the reply...
I am agreeing with u that its possible to include another.js file.
What i want is i am creating a website in that daily i want to update some static data and images.How is it possible using javascript

Deepa
Nov 29 '08 #7

gits
Expert Mod 5K+
P: 5,390
you just need to write another javascript file that you include in every page or just call with an ajax call and use it by a 'rendering script ... the idea could be like that:

texts.js

Expand|Select|Wrap|Line Numbers
  1. var texts = {
  2.     1: 'my first text', 2: 'my second text'
  3. }
  4.  
render.js

Expand|Select|Wrap|Line Numbers
  1. function write_text() {
  2.     var text = '';
  3.  
  4.     for (var i in texts) {
  5.         text += texts[i] + '<br/>';
  6.     }
  7.  
  8.     document.getElementsByTagName('body')[0].innerHTML = text;
  9. }
  10.  
page.html

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.         <script type="text/javascript" src="texts.js"></script>
  4.         <script type="text/javascript" src="render.js"></script>
  5.     </head>
  6.     <body onload="write_text();">
  7.     </body>
  8. </html>
  9.  
so just put the image-sources or texts int javascript objects and include them in the pages.

kind regards
Nov 29 '08 #8

P: 58
Hi,
I am having file like this....
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script type="text/javascript" src="dil.txt">
  4. </script>
  5. </body>
  6. </html>
  7.  
Here is it possible to access the content in the "dil.txt" file. I am not getting
Please help



Thanks in advance
Dec 1 '08 #9

Dormilich
Expert Mod 5K+
P: 8,639
javascript is supposed to read .js files (in your case it would be dil.js) but they must be located on the server (JS has no access to the local filesystem (maybe except when you use ActiveX)) and those files are supposed to hold JS code (in the best case all non-code is ignored)

regards
Dec 1 '08 #10

gits
Expert Mod 5K+
P: 5,390
threads merged - don't double post your questions and use code tags when posting source code ... please read the posting guidelines!

regards,
MOD
Dec 1 '08 #11

rnd me
Expert 100+
P: 427
@deegeorge
you can't use a non-javascript file as the .src of a script tag.
try this instead:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3. <script type="text/javascript">
  4. function IO(U) {var X = !window.XMLHttpRequest ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest;X.open( "GET", U, false);X.setRequestHeader("Content-Type", "text/html");X.send("");return X.responseText;}
  5.  
  6.   document.write(IO("dil.txt"));
  7.  
  8. </script>
  9. </body>
  10. </html>
  11.  

where dil.txt is in the same folder as the page.
Dec 1 '08 #12

P: 58
Hi,

Thanks a lot......
I am getting when i am trying to insert "dil.txt". The thing is that i have some images also so now i am putting in a word document and saving it as "test.doc". Is it possible to insert "test.doc" instead of "dil.txt".Pls help and also can u please explain the code that u have written.i didnt understand anything



Thanks a lotttttt ..........
Dec 2 '08 #13

Post your reply

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