0
在前端ejs頁面上,我有一個像這樣的ajaxSubmit處理函數。防止返回客戶端的ajaxSubmitHandler
$('#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
}
}
});
};
在服務器端,我有一個帶get和post方法的nodejs路由模塊。對於上面的提交按鈕點擊,我打電話 路線。像下面一樣
route.post('/submit', (req, res, next) => {
if (dataRetrieved == 1 || dataRetrieved == 2) {
return res.json({"responseCode" : dataRetrieved});
} else {
res.render('someOtherPage');
}
當應用程序沒有任何服務器問題時,else塊纔會執行。正如你所看到的,我想在我的else塊中渲染一些其他頁面,並且不希望將res.json返回到ajaxSubmit處理程序。它不允許我這樣做。只要它看到res.render,就會返回到submitHandler函數。有沒有辦法來防止這種情況?