Guest User

Untitled

a guest
Jan 26th, 2015
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.59 KB | None | 0 0
  1. You can change this:
  2. [HTML]
  3. <script type="text/javascript">
  4. $.ajax({  
  5.        url: 'http://api.facebook.com/method/links.getStats?urls=http://www.yahoo.com&format=json',  
  6.      success: function(data){    
  7.      $("#dd").html(data[0]['comment_count']);  
  8. } });
  9. [/HTML]
  10.  
  11. To this:
  12.  
  13. [HTML]
  14. $.ajax({  
  15.        url: 'http://api.facebook.com/method/links.getStats?urls=http://www.yahoo.com&format=json',  
  16.      success: function(data){
  17.     var count = data[0]['comment_count'];
  18.       $("#dd").html(count);
  19. $.ajax
  20.                     ({
  21.                       type: "POST",
  22.                       cache: false,
  23.                       url: "YOUR WEBSITE LINK TO PHP FILE",
  24.                       data: { stats: count },
  25.                       success: function(data) {
  26.                            //ignore response             
  27.                       },
  28.                       dataType: 'json'
  29.                     });  
  30. } });
  31. </script>
  32. [/HTML]
  33.  
  34. Now, when you send data to your server you need to have some PHP script which will accept that data and store it in database. You can do something like this:
  35.  
  36. [HTML]
  37. <?php
  38. if (isset($_POST["stats"])) {
  39.     $count = mysql_real_escape_string($_POST["stats"]);
  40.     mysql_query("INSERT INTO your-table-name (stats) VALUES ('$count')");
  41.    exit();
  42. }
  43. ?>
  44. [/HTML]
  45.  
  46. Please understand that this is not final code and will not work if you just put it on your website, but here you've done about 90% of what you need. Just make small changes in PHP script (to work with your database) and change URL in Javascript part and you're done.
  47.  
  48. Also, in this example I'm using MySQL instead of MySQLi which is not best practice, but that is what you've asked... Also, be sure to update your code to work with MySQLi.
Advertisement
Add Comment
Please, Sign In to add comment