【发布时间】:2016-08-31 22:50:53
【问题描述】:
我试图向我的控制器发送 AJAX 调用,其代码如下所示。现在我面临的问题是,即使我能够在控制器中检索数据并随后对其进行处理,它也不会通过 AJAX 调用返回到 jsp 页面。
@SuppressWarnings("unchecked")
@RequestMapping(value="/movie", method=RequestMethod.GET)
public @ResponseBody Person search(HttpServletRequest request, HttpServletResponse response) throws IOException{
String name = request.getParameter("uname1");
System.out.println(name);
List<Person> movie = personDAO.search(name);
Person per = new Person();
for (java.util.Iterator<Person> iterator = movie.iterator(); iterator.hasNext();){
per = iterator.next();
}
System.out.print(per + " Wtf");
return per;
}
这是我的 AJAX 调用:
$.ajax({
url: 'movie.html',
dataType: "json",
type: "GET",
contentType: 'application/json',
mimeType: 'application/json',
data: 'uname1=' + $('#element0').val(),
success: function(data){
$('#col1').text(data.name);
$('#col2').text(data.pname);
$('#col3').text(data.wname);
$('#col4').text(data.lname);
},
error: function(xhr, status, error) {
$('#col1').text("Undefined");
$('#col2').text("Undefined");
$('#col3').text("Undefined");
$('#col4').text("Undefined");
}
});
下面附上输出的屏幕截图: Eclipse Output
【问题讨论】:
标签: jquery ajax spring spring-mvc