I am trying to upload a file in MVC I have used following jquery code to get file on controller.
$(document).ready(function () {
window.addEventListener("submit", function (e) {
var form = e.target;
if (form.getAttribute("enctype") === "multipart/form-data") {
if (form.dataset.ajax) {
e.preventDefault();
e.stopImmediatePropagation();
var xhr = new XMLHttpRequest();
xhr.open(form.method, form.action);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
if (form.dataset.ajaxUpdate) {
var updateTarget = document.querySelector(form.dataset.ajaxUpdate);
if (updateTarget) {
updateTarget.innerHTML = xhr.responseText;
}
}
}
};
xhr.send(new FormData(form));
}
}
}, true);
});
I have taken this script from here
Its working file but when I want to run some other jquery script thats not firing here the code of that.
function OnUserSuccess() {
if ($("#UserDocumentID").val() == 0) {
mvcNotify.displayMessage("Record saved successfully.", "success");
} else {
mvcNotify.displayMessage("Record updated successfully.", "success");
}
}
I call it in Ajax.begin Form()
@using (Ajax.BeginForm("DocEdit", "User", new { EditUserID = ViewBag.EditUserID }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "UserPartialdiv", OnSuccess = "OnUserSuccess" }, new { enctype = "multipart/form-data", @class = "form-sm" }))
I am not much aware of jquery and new to mvc as well please be polite.