0

ページを読み込むdocument.on('click',...)と、条件に関係なくリクエストが即座に送信されます

例:

$(document).ready(function(){
  var poll = new Poll();

  if($('.loadPoll')[0]){ //this works fine
    poll.loadPoll(function(){
        console.log("loaded poll successful");

    });
  } 

 $(document).on('click', '#SubmitVote', poll.afterSubmit(function(){
        console.log("Poll has been voted on!");
    })); //this gets sent regardless of clicks


});

IDに要素がなくてもSubmitVote自動送信される

編集:

に変更:

 $(document).ready(function(){
   var poll = new Poll();

    if($('.loadPoll')[0]){
      poll.loadPoll(function(){
        console.log("loaded poll successful");

     });
    }
    $(document).on('click', 'button.SubmitVote', function(){
        poll.afterSubmit(function(){
            console.log("Poll has been voted on!");
            });
        });
}
4

1 に答える 1