www.webdeveloper.com
Results 1 to 2 of 2

Thread: Refresh .txt document every 10sec

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    4

    Question Refresh .txt document every 10sec

    HTML Code:
    function timer(){
    		setTimeout("timer()", 10000);
    		document.getElementById('log').value = "<?php include('logs/testFile.txt'); ?>";
    	}
    I have got timer() to run onLoad. The idea is to refresh the 'log' which is a textarea every 10 seconds. The data in the file is displayed in the textarea but if I make any changes to the testFile.txt it wont show in the textarea until i refresh the page, I want it to update on the page as it loops through the javascript function. What am I missing here?

  2. #2
    Join Date
    Mar 2012
    Location
    Saint-Petersburg, Russia
    Posts
    97
    I am sorry, but it looks that you completely do not understand or forget that javascript is executed in the browser (on client side) while php is executed on server, before browser receives the page at all.

    PHP code inserts the text which was in your log when page was asked from server.
    After browser receives it, it only replaces contents with the same text which was statically implanted in the page by php script, may be, minutes, hours or years ago.

    It resembles the person who reads again and again some old letter received from the fried long ago - one could not get new information from this old letter.

    You need your javascript to perform (by timer) ajax request to server for your log file and insert what you received in response. This may be performed without any PHP (if only log file is accessible not only from the php scripts - otherwise it should be requested from separate php-script).

    http://www.w3schools.com/ajax/ajax_example.asp
    Last edited by RodionGork; 03-06-2012 at 08:07 AM.

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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