Advertisement
Guest User

Untitled

a guest
Jun 28th, 2011
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.     wp_footer();
  3. ?>
  4.  
  5.         <script type="text/javascript">
  6.         // Added by Ajax_the_views
  7.         jQuery(document).ready(function($) {
  8.             var postIDs = new Array();
  9.             var i = 0;
  10.             // get a list of post id numbers that need the number of views
  11.             $('.ajax-the-views').each(function(){
  12.                 postIDs[i] = $(this).attr('id').replace('ajax-the-views-','');
  13.                 i++;
  14.             });
  15.             // create the JSON string to go to the server (only if there's a views field on the page)
  16.             if (postIDs.length > 0) {
  17.                 var sjcJSON = '{';
  18.                 for (i=0; i<=postIDs.length-1; i++) {
  19.                     sjcJSON += '"'+i+'":"'+ postIDs[i] + '"';
  20.                     if (i<postIDs.length-1) {
  21.                         sjcJSON += ',';
  22.                     }
  23.                 }
  24.                 sjcJSON += '}';
  25.                 // Send the Ajax request to the server and update the number of views appropriately
  26.                 var thisURL = '<?php echo wp_nonce_url( WP_PLUGIN_URL. '/ajax-the-views/ajax-the-views-server.php', 'do-you-really-want-to-see-the-views'); ?>&ajax_the_views='+sjcJSON;
  27.                 $.getJSON(thisURL , function(data) {
  28.                     for (i=0; i<=postIDs.length-1; i++) {
  29.                         $('#ajax-the-views-'+postIDs[i]).text(data[i]);
  30.                     }
  31.                 });
  32.             }
  33.         });
  34.         </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement