Last active
April 6, 2023 10:53
-
-
Save mikechau/6159049 to your computer and use it in GitHub Desktop.
Bootstrap Modal, ajax submit, and close on submit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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; | |
}); | |
*/ | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
bb hj
bb jhb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
asc