代码之家  ›  专栏  ›  技术社区  ›  user8486381

脚本功能在我使用后不起作用。load()函数

  •  0
  • user8486381  · 技术社区  · 7 年前

    我在一个表中添加数据,并阻止页面重新加载,所以我使用load函数只加载表并从中获取数据,而不重新加载页面。

    样本输出: enter image description here

    然后在我添加付款后: enter image description here

    我使用以下代码加载数据,而无需重新加载页面:

    $('#payment-body').load('client-info.php?id='+c_id+' #payment-body');
    

    现在我的问题是。如你所见,打印机图标后有一个X图标。

    我用这个图标设置函数。功能如下:

        $(".remove-transaction").click(function()
        {
        var p_id = $(this).attr("id");
        var c_id = $(this).attr("name");
        var remove_payment = $(this).attr("id"); 
    
        $.ajax({
            url: 'proccess.php',
            type: 'POST',
            async: false,
            data: {'p_id':p_id,'c_id':c_id, 'remove_payment':remove_payment},
            beforeSend : function(){
                $("#status").fadeIn(0).delay(2500).hide(0);
                $("#recieptModal_"+p_id).modal("hide");
                $("#statusModal").modal("show");
                $(".header-status").html('<h4>Please Wait...</h4>');
                $("#status").html('<h3 class="center"><em class="fas fa-sync fa-spin checking-client"></em> &nbsp; Deleting Payment...</h3>');
            },
            success: function(response){
                $("#status").fadeIn(0, function(){
                    $(".header-status").html('<h4>Done!</h4>');
                    $("#status").html('<h3 class="center"><em class="far fa-trash-alt invalid-client"></em> Payment Removed!</h3>');
                    $("#payment-row"+p_id).fadeOut('slow');
                    $('#total-paid').load('client-info.php?id='+c_id+' #total-paid');
                    $('#total-balance').load('client-info.php?id='+c_id+' #total-balance');
                    $('#remarks').load('client-info.php?id='+c_id+' #remarks');
                    window.setTimeout(function () {
                        $("#statusModal").modal("hide");
                    }, 3000);
                });
            },
            error: function(error){
                 console.log(error.responseText);
            //you could debug your php code if some error raises
            }
    
            });
        });

    当我重新加载页面时,它正在工作。但我想做的是让它在不重新加载页面的情况下工作。或者如你所见。只是使用。load()函数。

    1 回复  |  直到 7 年前
        1
  •  1
  •   Arvin Jason Cabrera    7 年前

    试着这样做,我认为这是因为新添加的数据函数不起作用,

     $(document).on('click', '.remove-transaction', function(){