First
The returned value is Map <String, Object>.
Controller writing
/**
* Error correction
* @ Author admin
*
*/
@ RequestMapping (value = "/checkQuestion. php ")
@ ResponseBody
Public Map <String, Object> checkQuestion (Long titleId ){
Map <String, Object> map = new HashMap <String, Object> ();
Map. put ("ceshi", "error correction passed back in the background ");
System. out. println (map. toString ());
Return map;
}
Page 1
$ ('. Other1'). click (function (){
$. Ajax ({
Url: '/vote/checkQuestion. Php ',
Data: $ ('# form1'). serialize (), // your formid
Success: function (data ){
If (data! = Null ){
Alert ("error correction" + data. ceshi );
}
}
});
})
<Form id = "form1">
<Input type = "hidden" name = "titleId" value = "$ {question. id}">
</Form>
Second
The returned value is a json string.
/**
* Add To Favorites
* @ 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", "back-end collection ");
Array. add (json );
System. out. println (array. toString ());
Return array. toString ();
}
Page description 2
$ ('. Other2'). click (function (){
$. Ajax ({
Url: '/vote/collectionQuestion. php? TitleId = '+ $ {question. id },
Success: function (data ){
If (data! = Null ){
Alert ("favorites" + data [0]. ceshi );
}
}
});
})