The code is working fine for me if the page is completely loaded But the issue is if the page is in loading mode I click on the link it reloads again how I prevent it from reloading.
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
e.preventDefault();
var key = $(e.relatedTarget).data('id');
$('#loadingmessage').show();
$.ajax({
type : 'post',
url : 'test.php',
data : 'key='+ key,
success : function(data) {
$('.modal-body').html(data);
},
complete: function() {
$('#loadingmessage').hide();
}
});
return false;
});
});
My Html is here
<a href='' data-toggle='modal' data-target='#myModal' data-id='1:2:3:4'>UP</a>
If page is completey loaded and i click on this the ajax call is works fine but when page is loading if i clcik the page starts reloading again how i prevent it to reload.
<div class="modal fade" id="myModal" 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">Check Server Status</h4>
</div>
<div class="modal-body">
<div id="loadingmessage">Checking...</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>