I have a bootstrap modal. When the user clicks the Update button it makes an ajax call to update the DB. However if the update fails for some reason I want to display the error message and leave the modal open.
Everything appears to be working in the order I expect, however the e.preventDefault()
doesn't appear to stop the modal from closing.
Why is the preventDefault()
not stopping the button from submitting?
My button:
<button type=submit class=btn btn-success id=btnUpdate style=margin-right:10px>Update</button>
Javascript button click code.
$(#btnUpdate).on(click, function (e) {
// reset the message...
$(#errorMessage).html();
// get the value...
var myParam = $(#someSelection).attr(someData);
var myParamData = JSON.parse(myParam );
updateData(myParamData.Name)
.done(function (result) {
if (!result.d == ) {
$(#errorMessage).html(result.d);
e.preventDefault();
}
else {
loadData();
}
});
});