1.前台页面:
//自定义一个回调函数ajaxDone
<form action="expert_BaseInformationSave.action?navTabId=expert_BaseInformationList&callbackType=closeCurrent&ajax=1"
method="post" class="pageForm required-validate" onsubmit="return validateCallback(this, ajaxDone)">
//回调函数
<script type="text/javascript">
function ajaxDone(json)
{
alert(json.expert.name);
}
</script>
2.后台代码:
public class Expert_BaseInformationSaveAction extends BaseAction implements SynchronizationData{
private Expert_BaseInformation expert_BaseInformation;
private JSONObject json;
public String execute() throws Exception {
Expert_BaseInformationManager expert_BaseInformationMgr = (Expert_BaseInformationManager)
SpringContextHolder.getBean(Expert_BaseInformation.class);
if(super.perExecute(expert_BaseInformation)!= null) return returnCommand();
expert_BaseInformationMgr.saveExpert_BaseInformation(expert_BaseInformation);
super.postExecute(expert_BaseInformation);
json = new JSONObject("expert", expert_BaseInformation, "name, gender, unit");
return "json";
}
public Expert_BaseInformation getExpert_BaseInformation() {
return expert_BaseInformation;
}
public void setExpert_BaseInformation(Expert_BaseInformation expert_BaseInformation) {
this.expert_BaseInformation = expert_BaseInformation;
}
public JSONObject getJson() {
return json;
}
}
注意:action中必须定义public JSONObject getJson() {
return json;
}, 否则前台无法获取json数据。
注:该文档由J-Hi爱好者"笨笨"提供,他的QQ号为289542213,欢迎大家与他在技术上多多交流