Struts2+ajax+json问题,求解???
返回时一直为undefined,非常郁闷,我把代码贴出来,大家看看!
js代码:
var url="${pageContext.request.contextPath}/updateHSwitch.action"; $.post(url,{isID:hsID,isSwitch:hsSwitch,dataType:"json",success:function(jsonres){ alert(jsonres); ? ? ? ? ? ? ?//?s??弹出??????undefined? var json = eval("(" + jsonres + ")"); alert(json);? ? ? ? ?//?s??弹出??????undefined? } }); public String updateHSwitch() { System.out.println("............."); if(isID==100) return "ERROR"; dataList=hostSwitchBiz.getHostSwitch(isID); //根据ID获取信息 for (int i = 0; i < dataList.size(); i++) { hostswitch=(SwHostswitch)dataList.get(i); } hostswitch.setIsSwitch(isSwitch); //替换开关状态数据 explanList=hostSwitchBiz.updateHSwitch(hostswitch); //更新整条数据 JSONArray jsonres=JSONArray.fromObject(explanList); System.out.println(jsonres.toString());?//??输出[{"isCommand":"#58008# ","isOpenExplain":"语音提示 ","isState":"内部空号音提示","isSwitch":"0","isShutExplain":"听空好音 ","isExplain":"内部空好音提示:1 语音提示,0 听空号音","isId":8}] return "jsonres"; }<package name="json" namespace="/" extends="json-default"> <action name="updateHSwitch" class="hostSwitchAction" method="updateHSwitch"> <result name="jsonres" type="json" /> </action> </package>?