AJAX 调用只工作一次

AJAX call only works once

本文关键字:一次 调用 工作 AJAX      更新时间:2023-09-26

我正在使用 AJAX 来检查用户输入 ID 是否在数据库中,如果它在那里,如果没有显示交叉标记,则会显示复选标记。

当我第一次输入数据库中的id时,

它工作得很好,如果我输入错误的id,它会显示十字标记,但是当我将错误的id更改为新的正确id时,复选标记不会出现。

jQuery(document).on("blur", '.iboxwrap input', function() {
    var value = jQuery(this).val();
    var crntEle = jQuery(this);
    var dateValve = jQuery("#paperpublishdate").val();
    if (value) {
        //alert(value);
        jQuery.ajax({
            type: 'POST',
            url: "<?php echo get_home_url(); ?>/wp-admin/admin-ajax.php",
            data: {
                action: 'checkwithDBlist',
                thedate: dateValve,
                theid: value
            },
            success: function(response) {
                if (response == 'Maching') {
                    jQuery(crntEle).closest('.iboxwrap').children("span").children("i").addClass('fa-check');
                } else if (response == 'Sorry') {
                    jQuery(crntEle).closest('.iboxwrap').children("span").children("i").addClass('fa-times');
                }
            },
            error: function(errorThrown) {
                alert("There was an Error in ID verification. Pleae manually check the IDs and continue");
            }
        });
    }
});

尝试删除以前的类:

 if (response == 'Maching') {
                    jQuery(crntEle).closest('.iboxwrap').children("span").children("i").removeClass('fa-times').addClass('fa-check');
                } else if (response == 'Sorry') {
                    jQuery(crntEle).closest('.iboxwrap').children("span").children("i").removeClass('fa-check').addClass('fa-times');
                }

你可以试试 jQuery(document).on("change", '.iboxwrap input', function() {....}