真心求解..ajax struts2 json交互 前台回调函数会Null
前台如下
$.ajax({
url : "findContentByid.action",
cache : false,
type : "post",
dataType : "json",
data : {mid : id},
success: function(data){
alert(data);
var json = eval("("+data+")");
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("读取服务器数据失败...");
}
});
<package name="ajaxmessage" extends="json-default" namespace="/">
<action name="findContentByid" class="messageAction" method="findContentByid">
<result type="json" name="findajaxmc">
<param name="root" >result</param>
</result>
</action>
</package>
public String findContentByid(){
Map<String, String> map = new HashMap<String, String>();
map.put("details", "a");
JSONObject jsonobject = JSONObject.fromObject(map);
result = jsonobject.toString();
System.out.println(getResult());
return "findajaxmc";
}
$.ajax({
url : "${ctx}/admin/testAction!findContentByid.action",
type: "post",
cache : false,
dataType : "json",
data : {mid : 'dd'},
success?:?function(data)?{
var json = eval("("+data+")");
alert(json.details);
},
error : function(e) {
alert(e);
}
});
public String findContentByid() {
Map<String, String> map = new HashMap<String, String>();
map.put("details", "a");
JSONObject jsonObject = JSONObject.fromObject(map);
System.out.println(jsonObject.get("details") + "--------");
//this.result = jsonObject.toString();
this.result= "{"details": "b"}";
return "findajaxmc";
}
<action name="testAction" class="testAction" method="findContentByid">
<result type="json" name="findajaxmc">
<param name="root">result</param>
</result>
</action>