请求未找到ajax spring mvc [英] Request not found ajax spring mvc
问题描述
我和人有一张桌子.当我单击删除图标时,我想从数据库中删除该人,并成功从表中删除该行.
我不断得到deleteEmployee?id=37 not found 404
.
我有一个@RequestMapping(value = "/deleteEmployee", method = RequestMethod.GET)
控制器.
我单击的人已从数据库中删除(选中),因此控制器应该没问题.但是为什么会出现错误?
I have a table with people. When I click on the delete icon, I want to delete that person from the database and on success delete the line from the table.
I constantly get deleteEmployee?id=37 not found 404
.
I have a controller with @RequestMapping(value = "/deleteEmployee", method = RequestMethod.GET)
.
The person I clicked was deleted from the database (checked) so the controller should be ok. But why do I get an error?
@RequestMapping(value = "/deleteEmployee", method = RequestMethod.GET)
public void deleteEmployee(@RequestParam(value = "id", required = true) int id) {
System.out.println(id);
employeeDAO.deleteEmployee(id);
}
$(document).on('click','.delete-emp', function(){
deleteEmployee(this);
});
function deleteEmployee(el){
var id = $(el).parent().attr('data');
console.log("delete: "+id);
$.ajax({
url: "deleteEmployee?id="+id,
success: function(){
deleteRow(id);
}
});
}
function deleteRow(el){
var row = $('.employee-row[data='+el+']');
var shiftRow = row.next();
console.log("deleting "+row+" "+shiftRow);
row.remove();
shiftRow.remove();
}
推荐答案
在方法中使用@ResponseBody注释就足够了.这将解决您的问题.
Use @ResponseBody annotaion in your method is alone enough . this will solve your problem .
@RequestMapping(value = "/android/api/home", method = RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody void Home(Locale locale, Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
//your logic
}
在ajax调用中添加内容类型
add the content type in ajax call
jQuery
.ajax({
url : controllerUrl,
data : oMyForm,
dataType : 'text',
processData : false,
contentType : false,
type : 'POST',
success : function(data) {
}
});
这篇关于请求未找到ajax spring mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!