【发布时间】:2015-07-22 19:36:04
【问题描述】:
我是 Spring MVC 的新手。我正在尝试在 Spring MVC 上执行 ajax 请求。这似乎是当 ajax 调用行为控制器方法没有响应时。但我不明白为什么会这样。 但我在浏览器控制台上收到此错误:
Failed to load resource: the server responded with a status of http://localhost:8080/spapp/ajaxtest.html 404 (Not Found)
这是我在控制器类中的方法:
@RequestMapping(value = "/ajaxtest", method = RequestMethod.POST)
public @ResponseBody String ajaxtest() {
String result = "This is Ajax text from ajaxTest Method";
return result;
}
这里是我在 index.jsp 中的 Ajax 调用:
$(function(){
$(document).on("click","button#save",function(){
$.ajax({
type:"POST",
url:"ajaxtest.html",
data:{test:"test"},
success:function(response){
$("div#response").html(response);
}
});
});
});
我该如何解决这个错误?
谢谢
【问题讨论】:
标签: java jquery ajax spring spring-mvc