jQuery此关键字在ajax响应中不起作用

时间:2019-05-06 15:56:25

标签: javascript jquery ajax this

我正在使用jquery this关键字来显示每个单击的弹出窗口的数据,如以下html所示。 Popover已加载到另一个Ajax响应中。

但是,除非我删除$(this).find('.cardDebit').html(data);并使用this,否则行$('.cardDebit').html(data);不起作用,但这不是最好的方法,因为它将数据添加到所有div中,而不是具体点击的那个。

$('.Btnclk').click(function () {
        $.ajax({
            type: 'POST',
            url: 'somephp.php',
            data: {//...}
            }).done(function (data) {
                $('#modal-res').html(data);
                $('.popover').click(function () {
                    $.get("layerData/ownerDebit.php")
                        .done(function (data) {
                            $(this).find('.cardDebit').html(data); //this doesn't work
                        });
                });
            })
    });

HTML:

<div class="popover popover-right">
     <button class="btn btn-primary w3-small">data</button>
     <div class="popover-container">
       <div class="card">
         <div class="card-body cardDebit">
        <!-- data should be shown here -->
         </div>
       </div>
     </div>
   </div>

0 个答案:

没有答案