发出警报后,jQuery事件停止工作

发出警报后,jQuery事件停止工作,jquery,click,Jquery,Click,我有一个jQuery事件,它在调用警报之前工作正常。该函数调用服务器上的脚本,将项目(在数据库中插入一行)添加到购物车。购物车中只允许有八个项目,因此当用户尝试添加第九个项目时,会向jQuery脚本返回一条不允许的消息。以下是jQuery脚本: jQuery(document).on('click', 'a.add.module, a.remove.module', function(e) { if (blnProcessing == true) { return fa

我有一个jQuery事件,它在调用警报之前工作正常。该函数调用服务器上的脚本,将项目(在数据库中插入一行)添加到购物车。购物车中只允许有八个项目,因此当用户尝试添加第九个项目时,会向jQuery脚本返回一条不允许的消息。以下是jQuery脚本:

jQuery(document).on('click', 'a.add.module, a.remove.module', function(e) {

    if (blnProcessing == true) {
        return false;
    } else {
        blnProcessing = true;
    }

    e.preventDefault();
    objLink = jQuery(this);
    strLink = objLink.attr('href');

    if (objLink.hasClass('add')) {
        objLink.text('Adding');
    } else {
        objLink.text('Wait');
    }

    jQuery.get(strLink, function(data) {
        if (data.success) {
            if (data.success != true) {
                alert(data.success);  // message that says this is not allowed -- this part stops the script from functioning further
            } else {
                // this part works
                jQuery('#cart').load('/study-clubs/modules/cart', function(){
                    if (objLink.hasClass('add')) {
                        strNewLink = strLink.replace('add', 'remove');
                        objLink.attr('href', strNewLink);
                        objLink.removeClass('add').addClass('remove').text('Added');
                    } else if (objLink.hasClass('remove')) {
                        strNewLink = strLink.replace('remove', 'add');
                        objLink.attr('href', strNewLink);
                            objLink.removeClass('remove').addClass('add').text('Add');
                    }

                    blnProcessing = false;

                });
            }
        } else {
            alert(data.error);
            blnProcessing = false;
        }
    }, 'json');
});

通常,对于这种行为,您使用
$(document).on('click','#someID',function()…
。但是我已经在使用它了。那么我需要重新连接事件侦听器还是什么的。我如何在警报后让它工作?

如果
数据。success
包含一个值,该值在布尔上下文中计算为true,但不等于
true
(因此执行包含
警报(data.success)
的块),您的
bln处理
标志永远不会重置


FWIW,我意识到有时需要额外的一双眼睛,但您真的应该能够通过在Firebug(或其他一组开发工具)中单步查看您的代码来了解这一点。

您希望在警报后运行什么代码?因为您使用的是
$.get()
?我预计此事件会再次触发。问题是,在服务器返回初始消息后,我在Firebug中再也没有收到任何消息。添加链接只是停止工作。我甚至无法控制台.log(数据).over data.success call,我的意思是。我知道如何使用Firebug。没有必要粗鲁。如果我被认为粗鲁,我道歉,这不是我的本意。如果你在单击处理程序中放置断点,尽管你应该看到它进入第一个if语句并返回false。如果我在get调用上方放置一个console.log,它会一直触发警报调用。就像事件处理程序正在分离。所有与add类的链接都停止工作。调用警报后,我无法console.log任何内容。@sehummel我是说它没有走那么远。在第一行放置一个断点。