我試圖向我的控制器發送一個AJAX調用,其代碼如下所示。現在我面臨的問題是,即使我能夠檢索控制器中的數據並隨後處理它,它也不會通過AJAX調用返回到jsp頁面。使用Spring MVC控制器調用Ajax
@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