jesh Posted November 7, 2006 Share Posted November 7, 2006 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 More sharing options...
aspnetguy Posted November 7, 2006 Share Posted November 7, 2006 not that I am aware of. Although you may be able to do soemthing with ActiveX objects (I know that sucks cuz it is only for IE) Link to comment Share on other sites More sharing options...
Chocolate570 Posted November 7, 2006 Share Posted November 7, 2006 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 More sharing options...
jesh Posted November 7, 2006 Author Share Posted November 7, 2006 Hmm. Thanks for the feedback. I think I'll just have to use a server-side solution. Link to comment Share on other sites More sharing options...
Chocolate570 Posted November 7, 2006 Share Posted November 7, 2006 Yea, that would be best. It's the most straightforward. Link to comment Share on other sites More sharing options...
Beta Posted November 9, 2006 Share Posted November 9, 2006 While we're on the Script/Text topic...is it possible to edit a .txt file through JS? Link to comment Share on other sites More sharing options...
jesh Posted November 9, 2006 Author Share Posted November 9, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now