469,925 Members | 1,449 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

How to read text file using JS without activex control?

I am trying to read text file , here is the code ,

I cant use activex control so plz give me some way....
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. function r()
  6. {
  7.     alert("Hkhi");
  8. var fh = fopen("G:\a.txt",0); // Open the file for writing
  9.  
  10. //var fh = fopen("C://Documents and Settings//Administrator//Desktop//log.txt",0);
  11. alert(fh);
  12. if(fh!=3) // If the file has been successfully opened
  13. {
  14.     alert("Hi");
  15.     var str = "Some text goes here...";
  16.     fread(fh, str); // Write the string to a file
  17.     fclose(fh); // Close the file 
  18. alert("Hi");
  19. }
  20.  
  21.  
  22. </script>
  23. </head>
  24. <body onload="r()">
  25. </body>
  26. </html>
Apr 4 '11 #1
8 11918
Dormilich
8,652 Expert Mod 8TB
you can’t do that. JavaScript is not allowed to access the client’s file system (ActiveX being the exception, obviously)

besides that, fopen(), fread() & fclose() are typical PHP functions (not sure about ActiveX, but it doesn’t seems like they belong there, too)
Apr 4 '11 #2
so you mean that its not possible to read file using js?

my problem is that I have to generate graph in html page using the parameter coming from one sensor , which are being stored in text file...

Is it possible to store this parameter somewhere and then accessed in js file? because I want that parameters in my file which is generating the graph..
Apr 4 '11 #3
Dormilich
8,652 Expert Mod 8TB
you can only access files from the server you serve your page from (cf. SOP (Same Origin Policy))
Apr 4 '11 #4
ok ,

So is it possible that I store parameters from local file using anyother language on webpage and the using JS access those parameters from that webpage?
Apr 4 '11 #5
Dormilich
8,652 Expert Mod 8TB
I donít know any language that could access the local filesystem (besides JScript).
Apr 4 '11 #6
thank for your help and reply ,

Now I just need to access the file on server ,
Can you please give me way to read our values from the file lying on the same folder on server...
Apr 4 '11 #7
Dormilich
8,652 Expert Mod 8TB
thatís simple, just do an AJAX request of the file.
Apr 4 '11 #8
thanks but I dont know too much about how to use AJAX , can you please just show me demo code for that....
Apr 4 '11 #9

Post your reply

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

Similar topics

1 post views Thread by rishka | last post: by
2 posts views Thread by Simon Verona | last post: by
1 post views Thread by sallu2000 | last post: by
7 posts views Thread by =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.