请求未找到ajax spring mvc
我有一张桌子。当我单击删除图标时,我想从数据库中删除该人,并成功从表中删除该行。我不断deleteEmployee?id=37 not found
404。我有一个控制器@RequestMapping(value = "/deleteEmployee", method =
RequestMethod.GET)。我单击的人已从数据库中删除(选中),因此控制器应该没问题。但是为什么会出现错误?
@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注释就足够了。这将解决您的问题。
@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调用中添加内容类型
jQuery .ajax({
url : controllerUrl,
data : oMyForm,
dataType : 'text',
processData : false,
contentType : false,
type : 'POST',
success : function(data) {
}
});
以上是 请求未找到ajax spring mvc 的全部内容, 来源链接: utcz.com/qa/401017.html