我正在使用 Ajax 在我的数据库中添加内容。这是代码:
function addToFavorites(){
var recipe_id = $("#recipe_id").val();
var url = connect_url+'addFavorite.php?user_id='+user_id+'&recipe_id='+recipe_id;
$.ajax({
type: 'POST',
data: [{
user_id: user_id,
recipe_id: recipe_id
}],
url: url,
async: true,
jsonpCallback: 'userCallback',
contentType: "application/json",
dataType: 'jsonp',
success: function (data) {
alert("HELLO!!!");
},
error: function (e) {
alert("ERROR!");
}
});
}
Ajax 调用成功,我能够在数据库中添加记录,但我只是想知道,如果调用成功,为什么它不显示警报消息?我的代码有问题吗?还是我的理解有问题?谢谢!