ajax返回json出错
ajax发送action请求要求相应json对象时,控制台有输出,说明action已经执行了,ajax的返回函数success没有相应,error和complete均有相应;
前台代码如下:
$.ajax({
url:"/lcgl_ssh/frame/main/checkpower.action?dt="+new Date().getTime(),
data:{"role":"管理员"},
dataType:"json",
type:"post",
success:function(data){
if(data.ok){
alert(data.ok);
$("#frmleft").attr("src","/lcgl_ssh/frame/lesson/flowAdministration.jsp");
}else{
alert(data);
alert(data.ok);
alert("权限不足!");
}
},
error:function(data){
alert("执行error");
},
complete:function(data){
alert("complete");
}
});
struts-main.xml文件配置:
<!-- 流程管理 -->
<action name="checkpower" class="com.xingao.action.main.CheckPowerAction">
<result name="success" type="json"></result>
</action>
action代码:
package com.xingao.action.main;
import com.xingao.action.XingaoAction;
import com.xingao.entity.W_user;
public class CheckPowerAction extends XingaoAction{
//input
private String role;
private W_user user;//从session中获取
//output
private boolean ok=false;
public String execute(){
System.out.println("checkpower被调用!");
user=(W_user) session.get("user");
if(user.getReadAndWritePrivilege()==1){
ok=true;
System.out.println(ok);
System.out.println(role);
}else{
ok=false;
System.out.println(ok);
}
System.out.println("checkpower调用结束!");
return "success";
}
public boolean isOk() {
return ok;
}
public void setOk(boolean ok) {
this.ok = ok;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public W_user getUser() {
return user;
}
public void setUser(W_user user) {
this.user = user;
}
}
当我把url:/lcgl_ssh/frame/main/checkpower.action输入到浏览器中就回报如下错误:
HTTP Status 500 -
--------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.struts2.json.
JSONException: org.apache.struts2.json.JSONException:
org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.xingao.entity.W_user.TRoleUsers, no session or session was closed
org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:243)
org.apache.struts2.json.JSONWriter.process(JSONWriter.java:165)
org.apache.struts2.json.JSONWriter.value(JSONWriter.java:131)
org.apache.struts2.json.JSONWriter.write(JSONWriter.java:99)
org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:112)
org.apache.struts2.json.JSONResult.execute(JSONResult.java:198)
com.opensymphony.xwork2.DefaultActionInvoca