“ajax:success” being called twice

后端 未结 1 877
后悔当初
后悔当初 2021-01-20 13:48

I\'m using jquery_ujs to send a simple post request. I bound a callback function to the \"ajax:success\" event. However, this callback is being called twice for each success

相关标签:
1条回答
  • 2021-01-20 14:46

    One of a few things are happening.

    Either you have multiple elements with .new_item class

    alert($(".new_item").length);
    

    you are sending the ajax request twice

    alert("Sending Request");
    $.ajax(...
    

    or you are binding the event twice

    alert("Binding Event");
    $(".new_item").bind("ajax:success", function(xhr, data, status) {
    

    Note: If you are using a modern browser, replace alerts with console.log()

    0 讨论(0)
提交回复
热议问题