编写了一个函数来使用jQuery-ajax. 一切似乎都是正确的,但它给出了 404 错误。
.js 文件:
function json(itemId, quantity, type) {
let item = {};
item["id"] = itemId;
item["path"] = window.location.pathname;
item["quantity"] = quantity;
$.ajax({
type: "POST",
url: "/test/ajax",
data: JSON.stringify(item),
dataType: "json",
contentType: 'application/json',
success: function (e) {
console.log("success!!!")
},
error: function (e) {
console.log("Error!!!")
},
done: function (e) {
console.log("Done!!!")
}
})
}
很可能,该错误是由于您没有禁用
csrf.要禁用
csrf-如果你不想禁用这个东西,你将不得不做一些事情:
Thymeleaf(JSP我不使用它):js-файл添加:最后,我们的 js 文件应该是这样的: