我已经为这个问题苦苦挣扎了两天。我用谷歌搜索并看到了一些类似的案例。
向服务器发送POST请求后,我想将页面重定向到另一个页面。 POST函数正常运行,但是window.location.assign()
方法不起作用(尽管它在我项目的另一部分中起作用)。
这是我的代码:
const $btnDel = $("<button>", {
appendTo: $('td:eq(0)', $tr),
"class": "revertButton",
html: "<i class='material-icons'>restore</i>",
on: {
click: function () {
console.log(`Reverting: ${book.name}`)
$.post(`/revert/${book.name}`, {
bookName: `${book.name}`,
pageCount: `${book.pageCount}`,
action: "REVERT"
}).done(() => {
window.location.assign('/bookPage');
})
}
}
});
第一个console.log有效(我的意思是console.log("Reverting: ${book.name}"
),但完成的功能不起作用。
答案 0 :(得分:0)
可以请您尝试以下代码。
const $btnDel = $("<button>", {
appendTo: $('td:eq(0)', $tr),
"class": "revertButton",
html: "<i class='material-icons'>restore</i>",
on: {
click: function () {
console.log(`Reverting: ${book.name}`)
$.post(`/revert/${book.name}`, () => {
bookName: `${book.name}`,
pageCount: `${book.pageCount}`,
action: "REVERT"
}).done(() => {
window.location.assign('/bookPage');
}).fail(function(error){
console.log(error);
})
}
}
});
希望这会给您一些帮助/线索。