日期:2014-05-16 浏览次数:20621 次
$(function() {
$("#look").click(function() {
alert("look");
var url = "json.action";
var params = {
name : "kobe"
};
$.post(url, params, function(data) {
alert("post");//此句一直没反应
$("#result").text("后台来的数据");
}, "json");
});
});
public class jsonAction extends ActionSupport{
private String result;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
// HttpServletResponse responce = ServletActionContext.getResponse();
// PrintWriter out = responce.getWriter();
System.out.println("后台");//此句已经执行
// out.println(result); 这一句测试过也不行
Map<String,String> map = new HashMap<String,String>();
map.put("name", "kobe");
map.put("age", "23");
JSONObject jo = JSONObject.fromObject(map);
result = jo.toString();
return SUCCESS;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}
<package name="default" namespace="/" extends="json-default">
<default-action-ref name="index" />
<action name="index">
<result>/index.jsp</result>
</action>
<action name="json" class="action.jsonAction">
<result type="json">
<param name="root">result</param>
</result>
</action>
</package>
&nbs