Advertisement
orksnork

Untitled

Nov 21st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Html to have count dumped into - Resides in the DOM.
  2.  
  3.  <p><span id="count"></span> is the current count number.</p>
  4.  
  5.  
  6. //Javascript call to retrieve count from external text source.  Call writeCount(); on Dom load to execute.
  7.  
  8. function writeCount(){
  9.         $.get( "count.txt", function(data) {
  10.             $("#count").html( data );
  11.             });
  12.     }
  13. //count.txt only contains the incremented number.
  14.  
  15.  
  16. // javascript function to increment the count.  calls external PHP file.  run pushScript(); whenever you want to increment the count (on load, on form submit, whenever);
  17.  
  18. function pushScript() {
  19.     $.ajax({ url: 'script.php' });
  20.     }
  21.    
  22.  
  23. //PHP file called that increments the count.
  24.  
  25. <?php
  26. $current = file_get_contents("count.txt");
  27. $new = $current + 1;
  28. file_put_contents("count.txt", $new);
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement