-1

I have a login page.I used jquery submit event.

 $("#frm_login").submit(function(event){
    event.preventDefault();  

   alert('submit tiggered!');

    });

The problem?The form is submitting twice!(Alert is showing twice.).

here is the actual code:

 <script type="text/javascript">
        $(document).ready(function () {

    $("#frm_login").submit(function(event){
    event.preventDefault(); 
    $("#login_invalid").hide();


    $.ajax({
      type:'POST'
      ,url:"<?=base_url('login/process_login')?>"
      ,data:$('#frm_login').serialize()
      ,dataType:'json'
      ,success:function(data){
        if(data['is_user']===undefined)
        {
          $("#login_invalid").show();
          $("#btn_submit_login").html('SUBMIT');
        }
        else {
       alert('submit triggered here twice!');

          if(data['user_type']==='1')
          {
            window.location='<?=base_url().'user'?>';
          }
          else if(data['user_type']==='0')
          {
            window.location='<?=base_url().'admin/maintenance/users'?>';
          }
        }

      }
      ,error:function(e){ 
        //alert(e.responseText);
      }
    });
    });

    });

</script>

I dont know whats wrong.I am using codeigniter based url in ajax.

Please help.

ktaro
  • 413
  • 1
  • 7
  • 24

1 Answers1

0

Found the answer!. This question is possible duplicate of : https://stackoverflow.com/a/26261975/10460838

e.stopImmediatePropagation();

saves my day! But i dont really understand why it needs that code.

ktaro
  • 413
  • 1
  • 7
  • 24