2010-07-23 63 views
1

人能否提供一個教程在那裏我可以在我的Spring MVC應用程序中使用JSON庫進行數據交換整合阿賈克斯?????我必須使用與阿賈克斯jQuery的在我的應用程序春天AJAX JSON jQuery的

回答

2
+0

我試着用這個教程...我已經下載了json2.2.3 jar文件.. 。它包含本教程中提到的flexjson.JSONSerializer類嗎?或者它們在一起不同? – apoorva 2010-07-23 11:23:10

+0

flexjson是http://flexjson.sourceforge.net/ – JoseK 2010-07-23 12:33:05

+0

額外庫,一個人在這裏者優先??? Flexjson還是spring-json? flexjson庫的任何地方都與flex有關嗎? – apoorva 2010-07-26 04:39:59

1

http://api.jquery.com/jQuery.ajax/ 這是很容易,你可以從RestEasy的開始如何實現基本RestWEbservice, 那麼你就可以從網頁Ajax調用該服務,然後從該服務JSON返回並解析它很容易,如果你找不到我可以幫你

春天裏寫控制研究呃這樣的服務

@GET 
    @Produces({MediaType.APPLICATION_JSON}) 
    @Path("getAllAlbums") 
    public String getAllAlbums() { 
     List<Album> albums = photoService.getAlbums(); 
     String albumListasJson = jgen.getFilteredJsonString(albums); 
     return albumListasJson; 
    } 

這是JSON庫

<dependency> 
      <groupId>net.sf.json-lib</groupId> 
      <artifactId>json-lib</artifactId> 
      <classifier>jdk15</classifier> 
      <version>2.4</version> 
     </dependency> 

和阿賈克斯

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

      } 
     } 
    }); 
}