我想通過Json作爲回調參數。任何人都可以糾正JavaScript從json對象獲取值?帶有JSON的Primefaces回調作爲回調參數
的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>
我看不出有任何JSON。 – SLaks
@SLaks我剛剛編輯並添加了服務器端代碼。你可以看到具有json格式的http響應輸出 – user1595858
JSF是一個基於組件的框架,你在做什麼不是JSF的方式...... 你想用JSON做什麼? 也許有最好的方法來實現它。 –