Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery update php array into javascript
    primarykey
    data
    text
    <p>Simplified version of my problem:</p> <p>Here is javascript example called <strong>example.html</strong> writes the content of a javascript array. </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/JavaScript"&gt; // javascript array called data data=[ [1,2],[3,4],[5,6] ] function WriteText(){ for(var i=0;i&lt;3;i++) document.write(data[i],"&lt;br&gt; ") } WriteText(); &lt;/script&gt; &lt;/head&gt; &lt;/html&gt; </code></pre> <p>Instead of array the values are written columns <strong>file.txt</strong> located in the same server directory where the <strong>example.html</strong> is. <strong>file.txt</strong> looks like that</p> <pre><code> 1 2 3 4 5 6 </code></pre> <p>I would like to accomplish the same functionality as the example above by reading this file with php and pass it to the javascript. <strong>file.txt</strong> is a log file where new values are being appended every few seconds So when new values are added I want to see the changes updated to screen. Here is <strong>getfile.php</strong> function that reads the file.</p> <pre><code>&lt;?php $values = array(); foreach(file("file.txt") as $line =&gt; $content) { $values[$line] = explode(' ',$content); } echo json_encode($values) ?&gt; </code></pre> <p>And here is the code that does this.</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery-1.5.2.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function WriteText(InputData){ for(var i=0;i&lt;InputData.length;i++) document.write(InputData[i],"&lt;br&gt; ") } //WriteText(data); setInterval($.get("getfile.php", { "func": "doSomething" },WriteText , "json"),1000); &lt;/script&gt; &lt;/head&gt; &lt;/html&gt; </code></pre> <p>I got this idea from <a href="http://api.jquery.com/jQuery.get/" rel="nofollow">http://api.jquery.com/jQuery.get/</a></p> <p>This code displays the <strong>file.txt</strong>. However when I manually append new values to the <strong>file.txt</strong> there is no update in the browser. If I refresh the page manually the new values are shown as well. So what am I doing wrong?? Is it the php script or probably I am not using the <code>setInterval()</code> properly. Thank you. </p>
    singulars
    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.
 

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