theodore 0 Posted January 9, 2008 Report Share Posted January 9, 2008 I am doing a coursework, and I have chosen HTML with JavaScript to do it.I have to read a text file and I have chosen AJAX to do it: function start(DocFile){ DocFile="file://"+DocFile; DocObject = getXmlHttpObject(getFileContent); DocObject.open("GET", DocFile , true); DocObject.send(null); }function getFileContent(){ if (DocObject.readyState==4 || DocObject.readyState=="complete"){ cDoc=DocObject.responseText; ....{main function} }} Originally, everything was alright. However, I have found that there is a big problem!!1. When I open the main webpage stored in a network drive, the webpage can only read text files from the drive but cannot read local drives files....2. When I upload the web page in a web hosting site, I cannot read any local files!!!Is this problem related to permission issue????I feel very sad about this problem. Please help me!!Do I have any other alternatives to read file???? (I don't want to include JAVA or swf or Applet)Thank you very very much!!! Quote Link to post Share on other sites
jesh 0 Posted January 9, 2008 Report Share Posted January 9, 2008 Try using relative paths rather than the "file" scheme. If you have a directory called "website" and the page that is using the ajax (index.html) and the text file that ajax is trying to open (text.txt) are both in that directory, then you can use the following: DocFile="text.txt"; Also keep in mind that unless you are using a web server to run this test locally, you're most likely not going to be getting any response codes from the ajax request (the readyState property may contain values that you don't expect). Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 9, 2008 Report Share Posted January 9, 2008 Is this problem related to permission issue????Yes - an AJAX request is only allowed to go to the same domain as the page making the request. So pages on domain.com can only send AJAX requests to domain.com, nowhere else. Using relative links will help if the files you want to request are on the web server hosting the page. It will only work with local files if you open the file locally (by double-clicking on it). I've actually never even tried to run an AJAX application without a web server, so I'm not sure if that will even work in the first place. Quote Link to post Share on other sites
theodore 0 Posted January 10, 2008 Author Report Share Posted January 10, 2008 Thank you!Is there any other methods (JavaScript) which can read files from local drives, with running a online webpage? Quote Link to post Share on other sites
Synook 47 Posted January 10, 2008 Report Share Posted January 10, 2008 No - again, for security issues. There is an ActiveX control (can't remember the name) that allows limited access but of course it would only work in Internet Explorer. Quote Link to post Share on other sites
justsomeguy 1,135 Posted January 10, 2008 Report Share Posted January 10, 2008 Yeah, that would be bad if you go to a website and it starts reading your files. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.