A set of technologies in .NET for building web applications and web services. Miscellaneous topics that do not fit into specific categories.
Hi @Kmcnet ,
Since you have had great help here on this thread, I would like to chime in with extra information that might be of help.
Your issue is likely caused by a race condition between the browser’s default form submission and the JavaScript event handler. Since the form uses <input type="submit">, the browser may begin submitting the form before JavaScript finishes running event.preventDefault(). On slower devices or when the page is under load, this race becomes more noticeable. The result is that the AJAX call is skipped, and the browser processes a full-page reload with the server’s partial view. Handling the form’s submit event instead of the button’s click event may avoid this timing issue.
I suggest handling it this way:
Instead of binding the click event on the submit button, attach the handler to the form’s **submit **event. This approach is more reliable across different devices and browsers. It ensures the default form submission is intercepted no matter how the form is submitted—by pressing Enter, clicking the button, or triggering a .submit() call in code.
$(document).ready(function () {
$('#frmupload').on('submit', function (event) {
event.preventDefault(); // Prevent default form submission
let form = $(this);
let url = form.attr('action');
$.ajax({
type: "POST",
url: url,
data: form.serialize(),
success: function (response) {
$("#divRESPONSE").html(response);
},
error: function (data) {
alert("Error occurred while submitting the form");
}
});
});
});
While trying this, keep type="submit" to catch submission paths at the form level.
Hope this helps resolve your issue, please let me know if it works out for you.