Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wp_footer();
- ?>
- <script type="text/javascript">
- // Added by Ajax_the_views
- jQuery(document).ready(function($) {
- var postIDs = new Array();
- var i = 0;
- // get a list of post id numbers that need the number of views
- $('.ajax-the-views').each(function(){
- postIDs[i] = $(this).attr('id').replace('ajax-the-views-','');
- i++;
- });
- // create the JSON string to go to the server (only if there's a views field on the page)
- if (postIDs.length > 0) {
- var sjcJSON = '{';
- for (i=0; i<=postIDs.length-1; i++) {
- sjcJSON += '"'+i+'":"'+ postIDs[i] + '"';
- if (i<postIDs.length-1) {
- sjcJSON += ',';
- }
- }
- sjcJSON += '}';
- // Send the Ajax request to the server and update the number of views appropriately
- 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;
- $.getJSON(thisURL , function(data) {
- for (i=0; i<=postIDs.length-1; i++) {
- $('#ajax-the-views-'+postIDs[i]).text(data[i]);
- }
- });
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement