jquery 没有刷新页面

the jquery is not refreshing page

$('.harvest-sch-grade-delete').click(function(){
    jQuery.ajax({
        url: "/smartfarm/control/deleteHarvestSchedule",
        type: "POST",
        data: {harvestScheduleId:$(this).attr("data")},
        success: function(data) {
            jQuery.ajax({
                url: "/smartfarm/control/ajaxHarvestScheduleList",
                type: "POST",
                data: {cropId:$('.harvest-sch-grade-delete').attr("val")},
                success: function(data) {
                    $('.harvest-schedule-list').html(data);
                    $(".alert-box-sch").html("Harvest Grade Schedule Deleted!!");
                    $('.alert-box-sch').show();
                    setTimeout(function() { $(".alert-box-sch").hide(); }, 5000);
                    $('.info-box-sch').hide();
                    $('.warning-box-sch').hide();
                    }
            });
        }
    });
});

我的删除功能工作了 2 次之后没有删除?我已经添加了一个用于 ajaxification 的 ftl 文件。

事件处理程序仅绑定到当前选定的元素;它们必须在您的代码进行事件绑定调用时存在于页面上。

在更新时 HTML。 您需要使用 Event Delegation using .on() 委托事件方法。

$(document).on('event','selector',callback_function)

代替document你应该使用最近的静态容器以获得更好的性能。

The delegated events have the advantage that they can process events from descendant elements that are added to the document at a later time. By picking an element that is guaranteed to be present at the time the delegated event handler is attached, we can use delegated events to bind the click event to dynamically created elements and also to avoid the need to frequently attach and remove event handlers.

对于你眼前的问题使用

$('.harvest-schedule-list').on('click','.harvest-sch-grade-delete', function(){
    //Your code
});

而不是

$('.harvest-sch-grade-delete').click(function(){
    //Your code
});