开发者

spring ajax json jquery

Can anybody suggest a tutorial where in I can integrate Ajax in my Spring MVC application using JSON library fo开发者_Python百科r data exchange????? I have to use jquery with ajax in my application


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


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


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

            }
        }
    });
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜