prevent bootstrap modal window from closing on form submission

后端 未结 7 1842
轻奢々
轻奢々 2021-02-05 06:47

Hi I\'m using Bootstrap for the first time and I can\'t get my modal form to stay open on clicking the submit button. I\'ve searched SO but all related questions deal with slig

7条回答
  •  时光取名叫无心
    2021-02-05 06:54

    This is how I did in my program, hope it helps.

    This is the button which triggers the modal. Here I have disable the keyboard and mouse click outside the modal.

    This is the modal div, with a form and a submit button. Replace ... with your modal content.

    
    

    Finally the function which triggers when you click submit button. Here event.preventDefault(); will prevent the default action of form submit, so that the modal will remain.

    function myFunction() {
        $("form").on("submit", function (event) {
            event.preventDefault();
            $.ajax({
                url: "yoururl",
                type: "POST",
                data: yourData,
                success: function (result) {
                    console.log(result)
                }
            });
        })
    }
    

提交回复
热议问题