我正在尝试将Json作为回调参数传递。任何人都可以更正javascript以获取json对象的值吗?
的javascript
function renderTopic(xhr,status,args){
alert("iam In renderTopic");
var topicObject = $.parseJSON(args.topicJSON);
for(var x in topicObject){
alert(x.topicBody);
};
}
服务器端
jGenerator.writeFieldName("topicBody");
jGenerator.writeStartArray();
...............
jGenerator.close();
context = RequestContext.getCurrentInstance();
System.out.println("JSON output in string "+out.toString())
XHTML
<p:commandLink action="#{topicController.listAllTopics}"
id="topicListAllCmdLink" value="" oncomplete="javascript:renderTopic(xhr, status,args)"/>
http响应
<partial-response><changes><update id="javax.faces.ViewState"><![CDATA[4091946826703479326:-2361306414195161728]]></update><extension ln="primefaces" type="args">{"topicJSON":"{\"topicBody\":[\"Test10\",\"Test22\",\"Test4\",\"Test11\"]}"}</extension></changes></partial-response>
答案 0 :(得分:0)
每件事似乎都没问题。你看到有什么错误吗?或者您可以告诉我们的任何输出。
请参阅此链接以获得更好的说明: Best method for passing Data from Java/JSF2 bean to Javascript/jQuery Components as return values