gpt4 book ai didi

jquery - Spring MVC ajax DELETE方法404错误

转载 作者:行者123 更新时间:2023-12-01 05:50:57 30 4
gpt4 key购买 nike

请帮助我理解。一切都完成得很好,但是一种方法不起作用,我遇到了 404 错误我有几个请求

function deleteFunc(id) {
$.ajax({
dataType: "json",
type: "DELETE",
url: "/BookList.vw/" + id,
async: true,
success: function (response) {
},
error: function (e) {
alert("Book doesn't found");
}
});
}

function modifyFunc(id) {
alert(id);
$.ajax({
dataType: "json",
type: "PUT",
url: "/EditBook.vw",
data: id,
success: function (response) {
},
error: function (e) {
alert('Server problems. You cannot modify this book.');
}
});
}

Controller :

@Controller
@RequestMapping("/BookList.vw")
public class BookListController {

@Autowired
private IBookService bookService;

public String getModelName() {
return "BookList";
}

public BookListController() {
}

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView openMain(Model m) throws Exception {
m.addAttribute("book", new Book());

Map<String, Object> model = new HashMap<String, Object>();
List<Book> books = bookService.listBooks();
model.put("books", books);

return new ModelAndView(getModelName(), "model", model);
}

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ModelAndView delete(@PathVariable int id) throws Exception {
bookService.removeBook(id);
return new ModelAndView(getModelName());
}

@RequestMapping(method = RequestMethod.POST)
public ModelAndView search(@ModelAttribute Book b) throws Exception {
List<Book> books = bookService.searchBook(b.getName().trim());
Map<String, Object> model = new HashMap<String, Object>();
model.put("books", books);

return new ModelAndView("BookList", "model", model);
}
}

搜索和主方法工作良好,但我不明白为什么 DELETE 方法出现错误,如下所示:

"NetworkError: 404 Not Found - http://localhost:8080/BookList.vw/2"

最佳答案

"NetworkError: 404 Not Found - http://localhost:8080/BookList.vw/2" 

我认为这个网址不正确,可能是这样的:

"NetworkError: 404 Not Found - http://localhost:8080/{ApplicationRoot}/BookList.vw/2"

关于jquery - Spring MVC ajax DELETE方法404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22505612/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com