javascript - 使用 .load() 函数后,脚本函数将无法工作

标签 javascript php jquery html

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

示例输出: 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() 函数。

最佳答案

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

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

关于javascript - 使用 .load() 函数后,脚本函数将无法工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50558254/

相关文章:

javascript - 添加更多文本时工具提示窗口更改高度和宽度

javascript - const 无法识别且未显示在控制台上

php - SQL JOINS检索并显示两次

javascript - JQuery 动画

javascript - 避免重复听众

jQuery $.ajax POST 多选选择

javascript - 在 javascript/jquery 中获取多个检查值

javascript - ng-change 不调用函数

php - Mysql正则表达式使用多个规则来匹配字符串

php - 选择前几个月的数据 - MySQL