I have a bootstrap modal which is loaded to DOM after ajax call. I have two buttons in my modal dialog. I have to call an ajax request when I click the #proceed button in the dialog modal. When I click the Cancel button, the modal will close immediately. The problem is when I click the #proceed button, it will be fire ajax request to the total number of times that I have clicked the modal dialog. In simple words, I have clicked modal dialog for 4 times and clicked the Cancel button to close , and when I click the #proceed button for the 5th time, it will fire ajax call 5 times. I have tried many things to reset the modal dialog, but it's not working.
Modal dialog Code:
<div class="modal fade" id="confirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Warning!!</h4>
</div>
<div class="modal-body">
The details entered cannot be edited later.Are you sure to proceed?
</div>
<div class="modal-footer">
<button type="button"id="closemodal" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" id="proceed">Proceed</button>
</div>
</div>
</div>
</div>
JS
$(document).on("click", '#confirm button#proceed', function(e) {
$('#confirm').modal('toggle');
});
$(document).on("click", '#confirm button#proceed', function(e) {
e.preventDefault();
$('#confirm').modal('toggle');
$.ajax({
type: 'POST',
url: "module/parents/covidqur/process.php",
processData: false,
contentType: false,
data: formData,
dataType:'text',
success:function(response){
console.log(5656565);
}
});
});