Here is how I did it in my program, hope this helps.
This is the button that launches the modal. Here I turned off the keyboard and mouse click outside the modal.
<button type="button" data-toggle="modal" data-target="#modalDivId" data-backdrop="static" data-keyboard="false">
This is a modal div, with a form and a submit button. Replace ... your modal content.
<div class="modal fade" id="modalDivId" role="dialog"> <form> ... <button type="submit" onClick="myFunction()" class="btn btn-success"> Submit </button> </form> </div>
Finally, a function that starts when you click the submit button. Here event.preventDefault(); will prevent the default action for the submit form, so the modal value will remain.
function myFunction() { $("form").on("submit", function (event) { event.preventDefault(); $.ajax({ url: "yoururl", type: "POST", data: yourData, success: function (result) { console.log(result) } }); }) }
source share