Skip to content

Instantly share code, notes, and snippets.

@agileminds1997
Forked from mikechau/ajax.js
Created September 10, 2022 08:51
Show Gist options
  • Select an option

  • Save agileminds1997/9f4ae811fbcdee56a61c762b4718f463 to your computer and use it in GitHub Desktop.

Select an option

Save agileminds1997/9f4ae811fbcdee56a61c762b4718f463 to your computer and use it in GitHub Desktop.
Bootstrap Modal, ajax submit, and close on submit
$(function(){
$('#myFormSubmit').click(function(e){
e.preventDefault();
alert($('#myField').val());
$('#myModal').modal('hide')
/*
$.post('http://path/to/post',
$('#myForm').serialize(),
function(data, status, xhr){
// do something here with response;
});
*/
});
});
<a href="#myModal" role="button" class="btn" data-toggle="modal">Launch demo modal</a>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
<form id="myForm" method="post">
<input value="hello" id="myField" type="hidden">
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary" id="myFormSubmit" type="submit">Submit</button>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment