Raja Manickam
Raja Manickam

Reputation: 1903

The event is not stop the firing in jquery

I have used the return false preventDefault stoppropogation but the the of them not stoping the condition to execute further when data is 1

  $(document).on('click','.lunch_out',function(e){ //lunch out
            var object = this;

            $.post('attendance_action.php',{'action':'check_time'},function(data){ //check the lunch time reached or not
                alert(data);
                if ($.trim(data) == '1') {
                    alert();
                    bootbox.alert("Sorry! Lunch time Over.");
                    $(object).remove();
                   // e.stopPropagation();
                    e.preventDefault();
//return false;
                }
            });
            $.post('attendance_action.php',{'action':'lunch_out'},function(data){
                window.location.reload();
            });
            e.preventDefault();
        });

Upvotes: 0

Views: 31

Answers (1)

Robin Carlo Catacutan
Robin Carlo Catacutan

Reputation: 13699

You should set else so the other post would run only if the data is not 1

$(document).on('click', '.lunch_out', function(e) { //lunch out
  var object = this;

  $.post('attendance_action.php', {
    'action': 'check_time'
  }, function(data) { //check the lunch time reached or not
    alert(data);
    if ($.trim(data) == '1') {
      alert();
      bootbox.alert("Sorry! Lunch time Over.");
      $(object).remove();
    } else { // your else 
      $.post('attendance_action.php', {
        'action': 'lunch_out'
      }, function(data) {
        window.location.reload();
      });
    }
  });
  e.preventDefault();
});

Upvotes: 1

Related Questions