Как позвонить с идентификатором, добавленным в строку данных - PullRequest
0 голосов
/ 04 февраля 2019

у меня есть модули, перечисляющие все данные о клиенте в таблице данных с действием использования кнопки.

Вопрос: Почему я не могу получить идентификатор кнопки, которую я добавил в строку, когда я нажимаюкнопка без предупреждения показывает, почему это происходит?

У меня есть мой ajax, чтобы перечислить всех клиентов в таблице

    $(document).ready(function(){
  $.ajax({
    url:'/logic_get_customer_data',
    type: 'GET',
    dataType: 'json',
    success:function(response) {

      var details = response.data;
      $.each(details, function (index, el) {

          var stringify = jQuery.parseJSON(JSON.stringify(el));

          var customer_name_each = stringify['customer_name'];
          var customer_address_each = stringify['customer_address'];
          var customer_email_each = stringify['customer_email'];
          var customer_number_each = stringify['customer_number'];
          var store_location_each = stringify['customer_location'];
          var customer_order_note_each = stringify['customer_order_note'];
          var customer_registered_each = stringify['customer_registered'];
          var customer_id_each = stringify['customer_id'];
          var action_each = '<button id="show_cart_button" class="btn btn-primary" type="button" value='+customer_id_each+' data-toggle="modal" data-target="#add_cart" ><i class="fas fa-cart-arrow-down"></i></button>';

          var t = $( "#tables" ).DataTable();
          t.row.add([customer_name_each,
            customer_address_each,
            customer_email_each,
            customer_number_each,
            store_location_each,
            customer_order_note_each,
            customer_registered_each,
            action_each]).draw();

        })
    }

  });
});

Моя функция клика для вызова идентификатора

$("#show_cart_button").click(function () {
  var fired_button = $(this).val();
  alert('George');
});

1 Ответ

0 голосов
/ 04 февраля 2019

Потому что он был добавлен после DOM.Используйте функцию on click и нацельтесь на что-то, что было в DOM до запуска ajax.

$("body").on("click", "#show_cart_button",function () {
  var fired_button = $(this).val();
  alert('George');
});
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...