2
WordPressのインストールでこの投票システムを使用しています。もし私が1枚しか持っていなければ、すべてうまく動作します.AJAX投稿は最初のフォームのみです。
だから、全ての投稿は、HTMLフォームがあります
<form method="post" id="vote_<?php the_ID(); ?>" class="vote" name="vote">
<input type="hidden" id="vote_post_id" name="vote_post_id" value="<?php the_ID(); ?>" />
<input type="hidden" id="vote_count" name="vote_count" value="1" />
<span class="votes_count"><?php echo get_post_meta($post->ID, 'votes', true); ?></span>
<input type="submit" name="vote_up" class="vote_up" value="+1" />
</form>
そして、ここでは、jQueryの:
$(function() {
$('form.vote').submit(function() {
var url = 'http://bla-bla.com/lib/';
post_id = $('input#vote_post_id').attr('value');
count = $('input#vote_count').attr('value');
form_id = $('form.vote').attr('id');
cast_vote = 'post_id=' + post_id + '&count=' + count;
original_count = $('span.votes_count').html();
new_value = parseInt(original_count) + 1;
//alert (cast_vote);return false;
$.ajax({
type: 'POST',
url: url + 'cast.php',
cache: false,
timeout: 10000,
data: cast_vote,
success: function(data){
$('form.vote').find('span.votes_count').fadeIn(1500, function() {
$(this).html(new_value);
});
$('form.vote').removeClass('vote').addClass('user_voted disabled');
}
});
return false;
});
});
だから私はこれが唯一のsubmitedされているフォーム上に、仕事をしたいです。どのように達成するのですか?
.each()が有効ですか?
ありがとうございました。 –