Omirion Posted August 24, 2010 Share Posted August 24, 2010 Hey there, Is there a way to get the contents of a txt file trough JS? Quote Link to comment Share on other sites More sharing options...
ceycey Posted August 24, 2010 Share Posted August 24, 2010 please some google.. var txtFile = new XMLHttpRequest(); txtFile.open("GET", "http://my.remote.url/myremotefile.txt", true); txtFile.onreadystatechange = function() { if (txtFile.readyState === 4) { // Makes sure the document is ready to parse. if (txtFile.status === 200) { // Makes sure it's found the file. allText = txtFile.responseText; lines = txtFile.responseText.split("\n"); // Will separate each line into an array } } } txtFile.send(null); http://social.msdn.microsoft.com/Forums/en-US/sidebargadfetdevelopment/thread/64ea2d16-7594-400b-8b25-8b3b9a078eab Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 What ceycey's suggesting you use is AJAX, by the way. This article explains it better, and the example he talks you through is to load a text file: http://www.openhosting.co.uk/articles/webdev/5899/ Quote Link to comment Share on other sites More sharing options...
AtlasC1 Posted August 24, 2010 Share Posted August 24, 2010 jQuery makes it really easy too, check out the first 'Try it Yourself' on w3c Schools jQuery AJAX. Pretty much all it involves is typing: "load('textfilehere.txt');". jm Quote Link to comment Share on other sites More sharing options...
Adam Posted August 24, 2010 Share Posted August 24, 2010 True, although if you're only going use jQuery for this one thing you need to think whether it's worth the extra bandwidth of loading the entire framework. Quote Link to comment Share on other sites More sharing options...
Alex Posted August 24, 2010 Share Posted August 24, 2010 True, although if you're only going use jQuery for this one thing you need to think whether it's worth the extra bandwidth of loading the entire framework. The entire jQuery framework is only about 24KB (when compressed). Quote Link to comment Share on other sites More sharing options...
Omirion Posted August 26, 2010 Author Share Posted August 26, 2010 What ceycey's suggesting you use is AJAX, by the way. This article explains it better, and the example he talks you through is to load a text file: http://www.openhosting.co.uk/articles/webdev/5899/ Very useful article just what i needed actually. 10x for the suggestions guys. jQuery is an option but I'm running on a tight KB limit, and I've already made my own animation code so not worth it. Quote Link to comment Share on other sites More sharing options...
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.