Note that there are some explanatory texts on larger screens.

plurals
  1. POis it possible to assign a value only once for php variable in continuous ajax request?
    primarykey
    data
    text
    <p>Well I have some simple text file, I am trying to read that file contents using php and update it to the user.I was setting up the ajax request for every 2 seconds but the problem is the file wont be updated for every 2 seconds may be 15 or 30 or 1 minute long.So i thought of doing this</p> <p>check the last modified time of file and if it is different then only update it to the user but here where I am stucked at.</p> <pre><code> Javascript functions function read() { read_text(); t=setTimeout("read()",200); } function read_text() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) { document.getElementById('read').innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","demo.php",true); xmlhttp.send(); } </code></pre> <p><strong>My php file</strong></p> <pre><code>&lt;?php $a = fileattime("filenam"); $b = fileattime("filenam"); if($b &gt; $a ) { echo "update contents"; $a = $ b; } ?&gt; </code></pre> <p>I thought to store the last modified time of file in <code>$a</code> variable and compare the value with <code>$b</code> variable but here <code>$a</code> will be overwritten with the new value for every ajax request. I want <code>$a</code> to be assigned a value only once, I mean for the first ajax request then later on compare it with <code>$b</code> value and if <code>$b</code> is greater than <code>$a</code> then update the contents to user then fill up <code>$a</code> with <code>$b</code></p> <p>but this is where i stucked at. Any help is greatly appreciated.Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload