Render List returned via JQuery
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.
精彩评论