无论我尝试什么,这个Ajax请求似乎都没有进入成功块。谁能告诉我发生了什么事?这让我发疯了。
$.ajax({
url: "/Index/AddItem",
type: "post",
contentType: "application/json",
data: JSON.stringify({
Srl: $("#Srl").val(),
Description: $("#Description").val(),
Comment: $("#Comment").val()
}),
headers: {
"RequestVerificationToken": "@TokenHeaderValue()"
},
dataType: "json",
success: function (data) {
alert("Done");
$('#tknGen').html(data);
}
});
我试图用响应数据替换a。但即使警报也没有被解雇。所以,我猜测成功块的问题
答案 0 :(得分:0)
试试这个
$.ajax({
url: "/Index/AddItem",
type: "post",
contentType: "application/json",
data: {
Srl: $("#Srl").val(),
Description: $("#Description").val(),
Comment: $("#Comment").val()
},
headers: {
"RequestVerificationToken": "@TokenHeaderValue()"
},
dataType: "json"
}).done(function (data) {
alert("Done");
$('#tknGen').html(data);
}).fail(function(jqXHR, textStatus, errorThrown) {
console.error(errorThrown);
});
“完成”和“失败”回调是自查询1.8以来处理结果的推荐方法(替换成功和错误)。 失败回调将显示有关服务器端抛出的错误的更多信息。