Jump to content
Sign in to follow this  
theodore

Help!! Help!! My text files cannot be read!

Recommended Posts

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!!! :)

Share this post


Link to post
Share on other sites

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).

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...