資源描述:
《jquery異步請求action返回json》由會員上傳分享,免費在線閱讀,更多相關內(nèi)容在工程資料-天天文庫。
1、Jquery異步請求Action返回JSON最近在自己寫分布式注冊中心的Web管理界面,需要點擊左邊樹節(jié)點時,請求后臺Action查詢該節(jié)點的詳細數(shù)據(jù),然后異步刷新右邊的節(jié)點信息區(qū)域。異步刷新用了Jquery對Ajax的封裝:1.function?zTreeOnClick(event,?treeId,?treeNode)?{??2.????????$.ajax({??3.????????????type:?"POST",??4.????????????url:?"Config.action",??5.????????????data:?"",??6.????????????dataTy
2、pe:?"json",??7.????????????success:?function(data)?{?????????????????8.????????????????alert(eval("("+data.result+")").word);??9.????????????????//$("#configInfo").load("nodeInfo.jsp");??10.????????????????//$("div?.configInfo").html(responseText);??11.????????????},??12.????????????error:?funct
3、ion()?{??13.????????????????$("#configInfo").load("error.jsp");???????????????14.????????????}??15.????????});???16.????};??Action寫成這樣:1.@SuppressWarnings("serial")??2.public?class?ConfigManageAction?extends?ActionSupport??3.{??4.????private?String?result;??5.??????6.????@Override??7.????public?
4、String?execute()?throws?Exception??8.????{??9.????????Map?map?=?new?HashMap();??10.????????map.put("word",?"word_A");??11.????????map.put("wordcount",33);???????12.????????JSONObject?json?=?JSONObject.fromObject(map);??13.????????this.result?=?json.toString();//給res
5、ult賦值,傳遞給頁面???14.????????return?SUCCESS;??15.????}??16.??17.??18.????public?String?getResult()?{??19.????????return?result;??good,noloosening.6.5.2DCSsidewiringtocompletetheenclosureandtheothersideafterthewiringiscompleted,DCSwithintheenclosurewhenthepowermoduleshouldbeloosenedorthepowergoesout.
6、6.6lowvoltagecableterminalmaking6.6.1first1.????}??2.??3.????public?void?setResult(String?result)?{??4.????????this.result?=?result;??5.????}??6.}??struts.xml配置:1.??2.
7、3//EN"??4.????"http://struts.apache.org/dtds/struts-2.3.dtd">??5.??6.??7.??8.??????9.??????10.??11