【发布时间】: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);
});
【问题讨论】:
-
您遇到什么错误?添加错误日志
-
状态码:404
-
可能你已经在
..../weburl -
它有2个“/web”,我不知道为什么,因为其他页面没有它,只是“/web”一次
标签: java ajax spring spring-mvc