Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a jQuery implementation that polls the server script every 1000ms and displays the result. Your typical response time + browser processing time should be significantly less than your polling interval or your requests might back-up.</p> <p><strong>Javascript:</strong></p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;eventCounter&lt;/title&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var interval = setInterval(function() { // this is where your ajax call is made. $.ajax('geteventcounter.php', { cache: false, dataType:'json', success: function(data) { // do your browser-side processing here. $('#eventCounter').text(data.eventcounter); } }); }, 1000); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;eventCounter is &lt;span id=eventCounter&gt;&lt;/span&gt;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p><strong>Server side PHP:</strong> For this example, uses a session variable which it increments on every request and returns a JSON string.</p> <pre><code>&lt;?php session_start(); // initialise counter, or increment it. if (isset($_SESSION['eventcounter'])) { $_SESSION['eventcounter']++; } else { $_SESSION['eventcounter'] = 0; } // set output mime type header("ContentType: application/json"); // copy session variable to a new array, convert to JSON and send. echo json_encode(['eventcounter' =&gt; $_SESSION['eventcounter']]); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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