Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the OP it looks like you want this data to be retained and accumulate for all users, so a server side component is necessary.</p> <p>Here is my take on it:<br> HTML</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;div id="p"&gt;Click here&lt;/div&gt; &lt;div id="results"&gt;&lt;/div&gt; &lt;script&gt; $('#p').click(function() { $.ajax("count.php", { complete: function(jqXHR, status) { $("#results").text(jqXHR.responseText); } }) }); &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>PHP </p> <pre><code>&lt;?php $clicks = intval(file_get_contents("clicks.txt")); $clicks++; $fp = fopen("clicks.txt", "w+"); fwrite($fp, $clicks); fclose($fp); //give the count to the user echo "result: $clicks"; </code></pre> <p>notice the php is the same but I now change the $clicks value to an integer after I get it from the file. </p> <p>You also need to ensure the files are read/write for the server... in linux you would just do this: </p> <pre><code>sudo chown -R www-data:www-data /var/www sudo chmod -R g+rw /var/www </code></pre> <p>to make your <code>www/</code> directory (or change it to the directory your Apache(?) server uses..) read/writeable by the server (this may be overkill, you can target specific files using the same method, just remove the <code>-R</code> (recursive) flag). </p> <p>I tested this setup locally and it works for me, goodluck!</p> <p>Edit: Just being nice.... </p> <p>Here is a no-jQuery solution to the JS (this won't work in all browsers, specifically older IE versions, I'll let you handle these :P )</p> <pre><code>var p_btn = document.getElementById('p'), results = document.getElementById('results'); p_btn.addEventListener('click', function() { var xhr = new XMLHttpRequest(); xhr.open('GET','count.php',false); xhr.onreadystatechange = function() { if( xhr.readyState === 4 &amp;&amp; xhr.status === 200 ) { while(results.hasChildNodes()) { results.removeChild(results.lastChild); } results.appendChild(document.createTextNode(xhr.responseText)); } } xhr.send(); }, false); // enjoy! </code></pre> <h1><a href="http://rlemon.net63.net/" rel="nofollow">Live Demo</a></h1> <p><em>Ignore the add code that gets spit back out from the server.... damn free hosts</em></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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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