Can anybody suggest a tutorial where in I can integrate Ajax in my Spring MVC application using JSON library for data exchange????? I have to use jquery with ajax in my application
3 Answers
http://www.jtraining.com/blogs/ajax-with-spring-mvc-and-jquery.html and http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=721#start
2 Comments
http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ has a good quick start
Comments
http://api.jquery.com/jQuery.ajax/ it is really easy ,you can start from restEasy how to implement basic RestWEbservice, then you can make ajax call from webpage to this service,then return from this service json and parse it very easy if you cant find i can help you
inside spring write a controller like this service
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("getAllAlbums")
public String getAllAlbums() {
List<Album> albums = photoService.getAlbums();
String albumListasJson = jgen.getFilteredJsonString(albums);
return albumListasJson;
}
this is json library
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<classifier>jdk15</classifier>
<version>2.4</version>
</dependency>
and ajax side
function getAlbums(){
$.ajax({
type: "GET",
url: "../rest/xxxx/" + userID,
dataType: "text", //"json"
cache : "false",
//content : "document.body",
success: function(msg) {
albums = "{\"albums\":" + msg + "}";
tplAlb = tmpls['viewId-01'];
if (tplAlb && albums) {
data = JSON.parse(aaaa);
if (data.albums.length == 0) {
$.post("../rest/cccccc/" + userID + "/" + "aaaaaaa");
getAlbums();
}
// alert(data.albums.length);
}
}
});
}