这是我的 nodeJS 代码:
app.post('/signup', function (req, res) {
res.status('500').send('showAlert');
});
这是我的 Html post 方法调用
$.post("/signup", userData, function(error){
if(error.responseText == 'showAlert')
{
alert("User already exists");
}
});
为什么我没有收到任何警报?
最佳答案
Status code
500
is indicator ofInternal Server Error
which is handled inerror
handler ofajax
.
jQuery.post( url [, data ] [, success ] [, dataType ] )
引用这个例子:
var jqxhr = $.post( "example.php", function() {
alert( "success" );
})
.done(function() {
alert( "second success" );
})
.fail(function() {
alert( "error" );
})
.always(function() {
alert( "finished" );
});
更新的代码:
$.post("/signup", userData, function(data) {
console.log(data);
}).fail(function(error) {
if (error.responseText == 'showAlert') {
alert("User already exists");
}
});
关于javascript - 没有从 nodeJS 中的 post 方法获得对 html 页面的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39761851/