ajax - “done()”函数在 JS 中没有触发
问题描述
我正在尝试使用 Thymeleaf 在 Spring Boot 中构建应用程序。我需要向服务器发布一些数据,为此我使用以下 Ajax 代码:
$(".info").on('click', function () {
var POSTdata = {
"day": $(this).attr("data-day"),
"date": $(this).attr("data-date")
};
console.log(JSON.stringify(POSTdata));
$.ajax({
url: "/shop/select/date",
type: "POST",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify(POSTdata),
success: function(){
console.log("suc");
}
}).done(function () {
console.log("sss");
}).fail(error => console.log(error))
});
但是 done() 没有触发。相反,它打印了很多行(来自失败回调),它们是更大数组的一部分,其中有一个字段显示 responseText: {"request":ok}
这是我发布到的功能:
@PostMapping("/shop/select/box")
public ResponseEntity<String> selectBox(@RequestBody String boxID, HttpSession session){
session.setAttribute("boxID", boxID);
System.out.println(session.getAttribute("boxID"));
return new ResponseEntity<>("boxID", HttpStatus.OK);
}
解决方案
推荐阅读
- swift - 在屏幕的某些部分禁用用户交互
- angular - 如何在页面初始化时自动完成显示所选项目
- wix - 检测并排安装?
- javascript - $.each 不尊重数组的顺序
- python - 对已打开的 django 频道消费者的 API 请求
- c++ - 试图了解标头中声明的类方法的 cpp 链接器错误
- microprocessors - 关于 8086 微处理器内存
- java - 如何使用 Mapbox 的 Annotation 插件在圆圈下画一条线?
- python - 合并的解密问题(rsaCipher +String)
- facebook - 如何确定是否来自 Facebook 的请求?