www.webdeveloper.com
Results 1 to 3 of 3

Thread: Get infomation form .txt file

  1. #1
    Join Date
    Dec 2011
    Posts
    79

    Get infomation form .txt file

    Back again, Firstly not to sure if this is possible with javascript but ill ask anyway

    I want to display the contents of a text file onto a few of my pages. The information in the file will change quite a bit, so it would be easier to edit one file rather then all of them, Is what I want to do possible with javascript? or could someone point me in the right direction of how.


    thanks

  2. #2
    Join Date
    Nov 2010
    Posts
    1,031
    it is only really possible with an AJAX request, something like the below...

    Code:
    function getData(callback) {
    url="data.txt"
    var txtFile = new XMLHttpRequest();
    	txtFile.onreadystatechange = function() {
       if (txtFile.readyState == 4) {
         callback(txtFile, txtFile.status);
       }
     };
    txtFile.open("GET", url, true); 
    txtFile.send(null);
    }
    
    getData(function(data) {		
    document.getElementById("display").innerHTML = data.responseText;
    });

  3. #3
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by xelawho View Post
    it is only really possible with an AJAX request, something like the below...

    Code:
    function getData(callback) {
    url="data.txt"
    var txtFile = new XMLHttpRequest();
    	txtFile.onreadystatechange = function() {
       if (txtFile.readyState == 4) {
         callback(txtFile, txtFile.status);
       }
     };
    txtFile.open("GET", url, true); 
    txtFile.send(null);
    }
    
    getData(function(data) {		
    document.getElementById("display").innerHTML = data.responseText;
    });
    Thanks you very much, I'll have a look into doing this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles