spring - 未找到使用 AJAX 的 Spring MVC 返回页面
问题描述
我创建了一个端点来删除记录,但是当我使用 POST 或 GET 时,我无法到达那个端点,它总是说找不到页面,我意识到附加了奇怪的参数。例子:
这是我的终点:
@RequestMapping(value = "/delete/completion/form/${id}", method = RequestMethod.GET)
@ResponseBody
public String deleteCompletionForm(@PathVariable("id") String id) {
return String.valueOf(completionFormService.deleteCompletionFormThenLog(id));
}
这是我的 ajax:
$('table').on('click', '.delete', function () {
if (confirm('Are you sure you want to remove this record!')) {
var contentPanelId = jQuery(this).attr("id");
$.ajax({
type: "GET",
url: "${pageContext.request.contextPath}/admin/panel/case/survey/delete/completion/form/" + contentPanelId,
cache: false,
timeout: 600000,
success: function (data) {
if (data) {
$(this).parents('tr').remove();
}
},
error: function (e) {
alert("Can not delete the record, please try again!")
}
});
}
});
解决方案
这是由于您指定的缓存设置将向 URL 添加时间戳参数而发生的。
来自 Jquery 文档(https://api.jquery.com/jQuery.ajax/):
缓存(默认值:true,对于 dataType 'script' 和 'jsonp' 为 false) 类型:Boolean 如果设置为 false,它将强制浏览器不缓存请求的页面。注意:将缓存设置为 false 仅适用于 HEAD 和 GET 请求。它通过将“_={timestamp}”附加到 GET 参数来工作。其他类型的请求不需要该参数,除非在 IE8 中对已由 GET 请求的 URL 进行 POST。
推荐阅读
- oracle - Oracle 程序不能正常工作?
- html - 使用引导程序删除两列之间的空间
- google-sheets - 如何格式化 Google 表格持续时间格式的单元格以以人类可读的格式显示天数、小时数和分钟数?
- android - 使用菜单项在 SurfaceView 上绘制 SVG 图像
- javascript - 如何通过反应中兄弟组件上的单击事件将图像加载到另一个组件中
- python - 在第二个轴上选择 Numpy
- java - 我怎样才能做一个慢循环?
- java - FirebaseMessagingService onMessageReceived 方法未在后台调用 DATA 有效负载
- sql - 是/否 查询列的格式
- python-3.x - ExcelLibrary - 机器人框架骑行 - 导入问题