Search code examples
javascriptjqueryajaxbootstrap-modalmodal-window

Form in modal window with Ajax doesn't work in FF?


so i have a simple form in a bootstrap modal window. Now with an ajax call i trigger a .php file which save the data or returns a error. In chrome and safari everything seems to work as expected, but in firefox it doesn't. In firefox after i hit the submit button the modal window disappears.

This is the javascript function which is triggered on submit form:

 function submitForm(){
            alert("submit data review");
                    var name = $('#add_owner_name').val();
                    var email = $('#add_owner_email').val();


            $.ajax({
                    type:'POST',
                            url:'add_ajax.php',
                            data:'contactFrmSubmit=1&owner_email=' + email + '&owner_name=' + name,
                            beforeSend: function () {
                                $('.submitBtn').attr("disabled", "disabled");
                                        $('.modal-body').css('opacity', '.5');
                                },
                            success:function(msg){
                                if (msg == 'ok'){
                                     $('#add_owner_name').val('');
                                        $('#add_owner_email').val('');

                                        $('#statusMsg').html('<span style="color:green;">Thanks for your suggestion.</p>');
                                } else{
                                    $('#statusMsg').html('<span style="color:red;">Some problems occurred, please try again.</span>');
                                }
                                    $('.submitBtn').removeAttr("disabled");
                                    $('.modal-body').css('opacity', '');
                            }
                    });
            }

What do i overlook? any suggestions


Solution

  • The page might be refreshing.

    Try placing event.preventDefault() at the top of your submit function.