I am working on modifying a plugin to allow users to vote on posts. My page looks something like this (though this is simplified of course):
<div class="vote vote1">
//voting buttons
</div>
<div class="vote vote2">
//voting buttons
</div>
<div class="vote vote3">
//voting buttons
</div>
<div class="vote vote4">
//voting buttons
</div>
As you can see, each voting div has a unique class associated with it, vote[id]. My trouble is that after submitting the vote to my vote.php file I need to refresh this unique voting div with the new data. I have been able to do this without trouble when I hardcode a particular voting div’s unique id into .load(), but I cannot seem to get this to work dynamically for all voting divs using a single script. Would somebody be able to help me out in refreshing the unique voting div that has been clicked?
<script type="text/javascript">
jQuery(document).ready(function(){
$(".vote a.can-vote").click(
function() {
var some = jQuery(this).parent();
var thepost = jQuery(this).attr("post");
var theuser = jQuery(this).attr("user");
var updown = jQuery(this).attr("up-down");
var is_update = jQuery(this).attr("update");
var votebox = ".vote"+thepost+" span";
jQuery.ajax({
type: "POST",
url: "<?php bloginfo('template_url'); ?>/vote.php",
data: {user: theuser, post: thepost, up_down: updown, update: is_update},
cache: false,
success: function( data ){
jQuery(some).load('http://mydomain.com div.vote[ID]');
}
});
return false;
});
});
</script>
I’m sorry if this is a simple question but I’ve been trying my best to figure it out for two days with no luck; thank you in advance for any help.
If I understood well:
you can do an ‘offline’ trick.
Just increment the vote number with jQuery, something like in this Ex:
The change will happen in the browser.
Than always on page refresh you’ll get back the real state from the DB.