【发布时间】:2014-03-12 04:13:39
【问题描述】:
我有一个 MVC Spring 控制器。我在页面加载时调用这个 ajax。
$.ajax({
type: "get",
url: 'custom/topic',
data: "email1=" + email1 + "&email2=" + email2 ,
async: false,
success: function(result) {
alert(result);
},
error: function (xhr, desc, error) {
window.alert('description' + desc);
window.alert('error' + error);
}
});
我的控制器是:
@RequestMapping(value="/topic", method=RequestMethod.GET)
public String topic(
@RequestParam("x1") String x1,
@RequestParam("x2") String x2) {
System.out.println("test");
String result1 = custom.topic(x1, x2);
return "test";
alert(result) 成功时,它会打印页面的整个代码。
【问题讨论】:
-
你能显示你的上下文配置吗?由于您使用的是 ResponseBody,因此只应输出结果字符串。
-
如果我删除 @responseBody 它仍然有同样的问题。
-
结果是字符串。
-
另外,如果我删除 @responseBody 并在控制器中返回一个字符串。出现同样的问题!
-
“结果”等于什么?确切的字符串将被发送到客户端。
标签: ajax spring-mvc