1

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 3

2

http://www.jtraining.com/blogs/ajax-with-spring-mvc-and-jquery.html and http://www.ajaxprojects.com/ajax/tutorialdetails.php?itemid=721#start

Sign up to request clarification or add additional context in comments.

2 Comments

I tried with this tutorial... i had downloaded the json2.2.3 jar file... Does it contain the flexjson.JSONSerializer class mentioned in this tutorial?????? Or is it all together different?
Which one''s prefered here??? Flexjson or spring-json?? is flexjson library anywhere related to flex???
2

http://blog.springsource.com/2010/01/25/ajax-simplifications-in-spring-3-0/ has a good quick start

Comments

1

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);

            }
        }
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.