首页 > 解决方案 > 未找到使用 AJAX 的 Spring MVC 返回页面

问题描述

我创建了一个端点来删除记录,但是当我使用 POST 或 GET 时,我无法到达那个端点,它总是说找不到页面,我意识到附加了奇怪的参数。例子:

http://localhost:8080/admin/panel/case/survey/delete/completion/form/0af9518a-8eea-4e69-94a3-3571c3785215?_=1526048495480

这是我的终点:

@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!")

            }
        });
    }

});

标签: springspring-mvc

解决方案


这是由于您指定的缓存设置将向 URL 添加时间戳参数而发生的。

来自 Jquery 文档(https://api.jquery.com/jQuery.ajax/):

缓存(默认值:true,对于 dataType 'script' 和 'jsonp' 为 false) 类型:Boolean 如果设置为 false,它将强制浏览器不缓存请求的页面。注意:将缓存设置为 false 仅适用于 HEAD 和 GET 请求。它通过将“_={timestamp}”附加到 GET 参数来工作。其他类型的请求不需要该参数,除非在 IE8 中对已由 GET 请求的 URL 进行 POST。


推荐阅读