Jump to content

Javascript and Text Files


jesh

Recommended Posts

I found a text file on the internet that displays the rainfall by hour for my neighborhood (it's been RAINING here in Portland) and it got me thinking about using that data for something.The problem is that it is just formatted text and is not an XML file and I have absolutely no control over the format or contents of this file.Now, I know that using ASP.NET, PHP, ASP, (insert your favorite server side solution here...) I can easily process that text file on my server and return it to my page in a way that I can use it. But I'd rather not go down that route yet.Anybody have any idea if it is possible to convert the contents of "somefile.txt" (publicly available on the internet, not on a client) to a string variable using only javascript?

Link to comment
Share on other sites

Well..it would be possible if you could make it so that inside the text file, the text is surrounded by a variable define. If that's true, then you could access the code with a <script src=""> and underneath, use the variable and format it as you like. But I'm not sure if you'd be able to. :)

Link to comment
Share on other sites

While we're on the Script/Text topic...is it possible to edit a .txt file through JS?
I've found that the answer to that is no. I'm a .NET developer and had to write a little block of code to fetch the text file and then parse it to get the data I needed which I then wrote to the screen. I then used AJAX to get that data from my server.C#:
string data = String.Empty;Uri url = new Uri("http://www.somewebsite.com/somefile.txt"); using (System.Net.WebClient client = new System.Net.WebClient()){	data = client.DownloadString(url);}// parsing went here...Response.Clear();Response.ContentType = "text/plain";Response.Write(data);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...