2011-01-19 4 views
2

나는이 투표 시스템을 WordPress 설치에 사용하면 더 많은 정보가 있으면 하나의 게시물 만 있으면 제대로 작동하며, 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()이 작동합니까?

답변

3

(단지 롤 날 무시하지 않은 경우) 내가 올바르게 이해하고 있다면 ...

당신은 모든 페이지에 버튼을 제출에 ...에 대한 참조를 유지하기 위해 .live 기능을 사용할 수 있습니다

$('.vote-up').live('click', function(){ 

     //do your ajax calls here... 

}); 

이것은 기본적으로 각 투표 버튼의 클릭 이벤트를 생성합니다 ...

+0

감사합니다. –