I am using Bootstrap v 3.0.0 . I follow the Bootstrap Modal HTML code:
<div class="modal fade" id="newModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">Submit Form</h4> </div> <div class="modal-body" style="max-height: 300px; overflow-y: auto;"> <br/> <form id="request_form" method="post" class="form-horizontal" enctype="multipart/form-data" action=""> <div class="form-group"> <label class="col-sm-4 col-sm-offset-1 control-label">Reg ID <span style="color:#FF0000">*</span> :</label> <div class="col-sm-5"> <input type="text" class="form-control" name="reg_id" id="reg_id"/> </div> </div> <div class="form-group"> <label class="col-sm-4 col-sm-offset-1 control-label">Reg Date<span style="color:#FF0000">*</span> :</label> <div class="col-sm-5"> <input type="text" class="form-control date_control" id="reg_date" name="reg_date" value="" placeholder="yyyy-mm-dd"> </div> </div> <div class="form-group"> <label class="col-sm-4 col-sm-offset-1 control-label">Upload Image<span style="color:#FF0000">*</span> :</label> <div class="col-sm-5"> <input type="file" name="reg_image" id="reg_image" accept="image/*" capture="camera" /> </div> </div> <div class="form-group"> <div class="col-sm-5 col-sm-offset-5"> <button type="submit" class="btn btn-success" id="btn_receipt_submit">Submit</button> <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button> </div> </div> </form> </div> </div> </div> </div>
For the above boot modal code, I wrote the following AJAX-jQuery code:
$('#request_form').submit(function(e) { var form = $(this); var formdata = false; var reg_id = $('#reg_id').val(); var reg_date = $('#reg_date').val(); if(window.FormData) { formdata = new FormData(form[0]); } var formAction = form.attr('action'); $.ajax({ url : 'xyz.php', type : 'POST', cache : false, data : formdata ? formdata : form.serialize(), contentType : false, processData : false, beforeSend: function() { $(".btn").prop('disabled', true); // disable both the buttons on modal }, success: function(response) { $(".btn").prop('disabled', false); // enable both the buttons on modal var responseObject = $.parseJSON(response); if(responseObject.error_message) { if ($(".alert-dismissible")[0]) { $('.alert-dismissible').remove(); } var htmlString = "<div class='alert alert-danger alert-dismissible' role='alert'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>×</button>"+responseObject.error_message+"</div>"; $(htmlString).insertBefore('div.modal-body #request_form'); } else { $('#newModal').modal('hide'); $('#Modal2').modal('show'); } } }); e.preventDefault(); });
I want to show the corresponding loader image exactly in the center of the screen along with the message "Your request is being processed ... wait" when the AJAX request is sent to the PHP file and it should be displayed exactly on the center of the screen until the response from the PHP file appears.
Also during this time, the user should not be able to close the modal, and he should not hide if the user clicks somewhere separately from the modal. In other words, until a response from the PHP file is received, the user cannot do anything.
I tried many tricks, but I can turn off the two buttons that appear on the form until the answer comes up. But actually I want to do much more.
user4225623
source share