开发者

Render List returned via JQuery

开发者 https://www.devze.com 2023-02-19 00:45 出处:网络
On the server side, I have a list into a bean. On the Client side, I use: function callJava() { $.getJSON(\"../reference/test\", { name: $(\'#name\').val()}, function(result) {

On the server side, I have a list into a bean. On the Client side, I use:

function callJava() {   
 $.getJSON("../reference/test", { name: $('#name').val()}, function(result) {
                开发者_JS百科         // result is a bean that has a list 
           alert(result.fooList.length);
 });
 }

I need to be able to render this list later via FreeMarker. What is killing me when I replaced this list with a String variable, it works fine like:

function callJava() {   
 $.getJSON("../reference/test", { name: $('#name').val()}, function(result) {
 alert(result.stringVariable)

 });
 }

How could I deal with the string into that bean !!


If all you want to do is manipulate the elements of the list:

function callJava() {   
   $.getJSON("../reference/test", { name: $('#name').val()}, function(result) {
     for (var i = 0; i < result.fooList.length; ++i)
       alert(result.fooList[i]);
   });
 }


Actually I have just an update over my question is that the list I'm trying to return from the server side is a SCALA list . I have solved this issue by using an array instead of JAVA . and it works fine by using the following as Pointy said :

function callJava() {   
   $.getJSON("../reference/test", { name: $('#name').val()}, function(result) {
     for (var i = 0; i < result.fooList.length; ++i)
       alert(result.fooList[i]);
   });
 }


Could you capture the JSON response and post it? The jQuery getJSON method will silently swallow any parsing errors from malformed JSON. That is probably what happened.

0

精彩评论

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

关注公众号