I have bootstrap modal. When the user clicks the Refresh button, he calls an ajax call to update the database. However, if the update fails for some reason, I want to display an error message and leave the mod open.
Everything seems to work in the order that I expect, however e.preventDefault() does not stop closing the modal.
Why preventDefault() does not stop button submission?
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(); } }); });
source share