第一种
返回值是 Map
控制器写法
/**
* 纠错 问题
* @author admin
*
*/
@RequestMapping(value="/checkQuestion.php")
@ResponseBody
public MapcheckQuestion(Long titleId){
Mapmap = new HashMap();
map.put("ceshi", "后台传回来的纠错");
System.out.println(map.toString());
return map;
}
页面写法一
$('.other1').click(function(){
$.ajax({
url:'/vote/checkQuestion.php',
data:$('#form1').serialize(),// 你的formid
success:function(data){
if(data!=null){
alert("纠错"+data.ceshi);
}
}
});
})
第二种
返回值是 json 的 字符串
/**
* 收藏 问题
* @author admin
*
*/
@RequestMapping(value = "/collectionQuestion.php",produces = "application/json; charset=utf-8")
@ResponseBody
public String collectionQuestion(){
JSONArray array=new JSONArray();
JSONObject json= new JSONObject();
json.put("ceshi", "后台传回来的收藏");
array.add(json);
System.out.println(array.toString());
return array.toString();
}
页面写法二
$('.other2').click(function(){
$.ajax({
url:'/vote/collectionQuestion.php?titleId='+${question.id},
success:function(data){
if(data!=null){
alert("收藏"+data[0].ceshi);
}
}
});
})