提交Ajax帖子时,我似乎无法使Ajax成功功能正常工作。您是否知道为什么会这样?失败也不会触发,因此某些操作无法正常进行。这是我要建立的投票系统,因此在上投票时,它会提交POST;在下投票时,它会提交POST。
$('.up').on('click', function() {
var id = this.id;
var cardId = JSON.stringify({ cardId: id });
$.ajax({
type: "POST",
url: "/api/upvote",
data: cardId,
contentType: "application/json; charset=utf-8",
success: function(resp){
console.log(resp)
},
failure: function(error) {
console.log(error)
}
});
});
$('.down').on('click', function() {
var id = this.id;
var cardId = JSON.stringify({ cardId: id });
$.ajax({
type: "POST",
url: "/api/downvote",
data: cardId,
contentType: "application/json; charset=utf-8",
success: function(resp){
console.log(resp);
},
failure: function(error) {
console.log(error);
}
});
});