On the front end ejs page, I have a ajaxSubmit handler function like this.
$('#submitDetails').submit(function() {
$(this).ajaxSubmit({
error: function(xhr) {
alert('Error: ' + xhr.status);
},
success: function(response) {
if (response.responseCode == 1) {
alert("There is an error. Please try again!");
} else {
//do nothing
}
}
});
};
On the server side, I have a nodejs routing module with get and post methods. For the above submit button click, I am calling a post route. Like below
route.post('/submit', (req, res, next) => {
if (dataRetrieved == 1 || dataRetrieved == 2) {
return res.json({"responseCode" : dataRetrieved});
} else {
res.render('someOtherPage');
}
When the application works without any server issue, the else block only executes. As you could see, I want to render some other page inside my else block and do not wish to return res.json to the ajaxSubmit handler. It is not allowing me to do that. As soon as it sees res.render, it goes back to that submitHandler function. Is there a way to prevent this?