Front desk:
$.ajax ({
URL: "Searchxxx.do",
Type: "Post",
DataType: "JSON",
Async: "True",//Asynchronous request
data:{"name": Settname, "id": 1},
Success:function (data) {
Alert (data)
$.each (data, function (I,item) {//I: Gets the object's subscript, item: Gets the value of the object
Alert (item.tribeid+ "," +item.tribename);
});
},
Error:function () {
Alert ("Error")
}
});
Background:
List<> list=new arraylist<> ();
list=......;//querying a collection of objects into a list
Jsonarray obj = jsonarray.fromobject (list);
return obj.tostring ();
To prevent Chinese garbled characters from appearing in JSP pages, add produces = "text/json;charset=utf-8" in Requestmapping in controller
@RequestMapping (value = "Manager/searchtribelikename", produces = "text/json;charset=utf-8")
@ResponseBody
AJAX enables front-and back-end interaction in SPRINGMVC (backend collection, foreground Fetch collection Object)