【问题标题】:ERROR 404: ajax can't connect to the @requestmapping错误 404:ajax 无法连接到 @requestmapping
【发布时间】:2020-11-27 12:48:21
【问题描述】:

我的 ajax 无法连接到这里,当我看到 F12->Network->Headers 我看到 requestUrl 有双“/web”:http://localhost:8080/create_user_web_war_exploded/web/web/done 但是我的删除页面在链接 @RequestMapping(value = "/web/delete",method = RequestMethod.GET) 处只有 1 个“/web”。我认为在我的网站上出现错误 404,因为所有其他页面的链接都是“/'project_name'/'Request value'”

//My controller
@RestController
@RequestMapping(value = "/web/done")
public class UserController {
    @Autowired
    private IUserService userService;

    @DeleteMapping
    public String delete( @RequestBody UserDTO model,@PathVariable("id") long id){
        ModelAndView mav = new ModelAndView("web/done");
        userService.deleteUser(model.getId());
        return "done";
    }

}
//My ajax
function deleteUser(data) {
    console.log("hihi");
    console.log("done");
    $.ajax({
        type: 'DELETE',

        url: 'web/done',
        data: data,
        /*dataType:'json',*/
        /*contentType:'application/json',*/
        success: function () {
            console.log("done");
        },


    }).done(function (response) {
        alert("Job done!!!!");
    }).fail(function (xhr, status, error) {
        alert(xhr.responseText);
    });

【问题讨论】:

标签: java ajax spring spring-mvc


【解决方案1】:

控制器的主要映射是“/web/done”,但在主要方法上,您只调用“web/done”而没有第一个 /。尝试在 Ajax 上添加 /

【讨论】:

  • 仍然无法正常工作,在其他页面中我仍然喜欢它并且它可以工作(这是 IDEA 的建议,所以我只需要按 Enter,我认为这不是问题,但它可以解决问题双重“/web” - 我不知道为什么),这里它不起作用,仍然错误 404
猜你喜欢
  • 2017-09-18
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
  • 1970-01-01
  • 2020-06-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多