click - jQuery event stops working after alert -
i have jquery event works fine until alert called. function calls script on the server adds item (inserts row in database) cart. 8 items allowed in cart, when user tries add ninth item, message returned jquery script that not allowed. here jquery script:
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 says not allowed -- part stops script functioning further } else { // 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'); });
ordinarily, kind of behavior, use $(document).on('click', '#someid', function() ...
. i'm using that. need reattach event listener or something. how work after alert?
if data.success
contains value evaluates true in boolean context not equal true
(ergo block containing alert(data.success)
executed), blnprocessing
flag never reset.
fwiw, realize takes pair of eyes, should have been able figure out stepping through code in firebug (or set of developer tools).
Comments
Post a Comment