2017-03-25 8 views
-1

ボタンをPHPファイルからエコーしました。 そのボタンをクリックすると、複数回発生します。それはなぜそれのように振る舞うのですか?ボタンをクリックしてイベントを複数回起動する

私はここでstackoverflowで見つけたいくつかの解決策を行いましたが、動作しませんでした。 提案や修正はありますか?

$(document).on('click','#reserve',function(){ 
     if (myclid != '0') { 
     if (ll.charAt(0)=='b') { 
      alert(lnk2); 
      $.ajax({ 
       url: "reserve_func.php", 
       method: "POST", 
       data: {reserve_id:random_numbers, myclid:myclid, myclient:myclient, lnk2:lnk2, clid:clid}, 
       success: function(data) { 
        if (data == 'true') { 

        getResDate(); 
        } else if (data== 'exceeded') { 

         pop(); 
         $('#notice').html('Client <b style="text-transform: capitalize;">'+myclient +'</b> has two (2) lots that were still reserved and are not yet paid.'); 
        } else { 

         pop(); 
         $('#notice').html(data); 
        } 
       } 
      }); 
     } 
     } else if (myclid=='0') { 

     $('#pop_bg').fadeIn('fast'); 
     $('#pop_c').slideDown('fast'); 
     $('#notice').fadeIn('fast'); 
     $('#notice').html('Please select a client!'); 
     } else { 

     $('#pop_bg').fadeIn('fast'); 
     $('#pop_c').slideDown('fast'); 
     $('#notice').fadeIn('fast'); 
     $('#notice').html('Please add your client first! Click <a href="profile.php">here</a> and then select <b>My client(s)'); 
     } 
}); 
+1

'submit'ボタンボタンですか?そうであれば、 'event.preventDeault()'を使用してフォームの送信を停止し、AJAXを実行して – RiggsFolly

+0

@RiggsFollyにしてください。それは

+0

だったので、 '

答えて

-1

これを確認してください。

$("#reserve").on("click", function(event) { 
 
\t event.preventDefault(); 
 
\t var install = $('#gt').val(); 
 
     if (myclid != '0') { 
 
     if (ll.charAt(0)=='b') { 
 
      alert(lnk2); 
 
      $.ajax({ 
 
       url: "reserve_func.php", 
 
       method: "POST", 
 
       data: {reserve_id:random_numbers, myclid:myclid, myclient:myclient, lnk2:lnk2, clid:clid}, 
 
       success: function(data) { 
 
        if (data == 'true') { 
 

 
        getResDate(); 
 
        } else if (data== 'exceeded') { 
 

 
         pop(); 
 
         $('#notice').html('Client <b style="text-transform: capitalize;">'+myclient +'</b> has two (2) lots that were still reserved and are not yet paid.'); 
 
        } else { 
 

 
         pop(); 
 
         $('#notice').html(data); 
 
        } 
 
       } 
 
      }); 
 
     } 
 
     } else if (myclid=='0') { 
 

 
     $('#pop_bg').fadeIn('fast'); 
 
     $('#pop_c').slideDown('fast'); 
 
     $('#notice').fadeIn('fast'); 
 
     $('#notice').html('Please select a client!'); 
 
     } else { 
 

 
     $('#pop_bg').fadeIn('fast'); 
 
     $('#pop_c').slideDown('fast'); 
 
     $('#notice').fadeIn('fast'); 
 
     $('#notice').html('Please add your client first! Click <a href="profile.php">here</a> and then select <b>My client(s)'); 
 
     } 
 
});

+0

なぜ 'live()'を使うのですか?そのメソッドはjQuery 1.7(私が思う)では廃止され、jQuery 1.9から完全に削除されました。 –

+0

申し訳ありませんが、私はこれを忘れました。今、私は訂正しました。 –

+0

@ user2053851あなたのコードを試しましたが、今は起動していません:/ – phpwev

関連する問題