I have this ajax code that if the data
is true
it will show a modal if it is false
it will submit the form/page and let the servlet in that form handle everything. I want that page to reload/ to redirect to another page from servlet..
$("#UploadFileExcel").submit(function (event) {
var page = document.getElementById('UplaodFilePage').value;
var year = document.getElementById('year').value;
event.preventDefault();
$.ajax({
url: "UploadCheckerServlet",
type: 'POST',
dataType: "JSON",
data: {
censusYear: 2018,
page: page
}, success: function (data) {
alert(data);
if (data === true) {
alert("lalala" + data);
$("#ShowSheets").modal("show");
} else if (data === false) {
alert("PAGE");
alert(this);
alert(year);
$(this).submit();
}
}, error: function (XMLHttpRequest, textStatus, exception) {
alert(XMLHttpRequest.responseText);
}
});
});
I already try bind and unbind
from other questions but it still wont work.
The code works either submitting form even if should not, i tried to put the event.preventDefault();
inside the if statement
but it still submits while when it is outside it wont submit form
Aucun commentaire:
Enregistrer un commentaire