Action里返回参数的方法:
public String selcetUserInfo() throws Exception {
String second = "第2个参数";
JSONObject jsonObj = new JSONObject(json);
String name = jsonObj.getString("name");
int num = Integer.parseInt(jsonObj.getString("num"));
result = this.selcetUserInfo.selcetUserInfo(name, num);
getResponse().addHeader("Pragma", "no-cache");
getResponse().setCharacterEncoding("utf-8");
JSONArray jsonArray2 = JSONArray.fromObject(result);
getResponse().getWriter().write(jsonArray2.toString());
return null;
}
JS AJAX取返回参数方法为:
function onLoad() {
$.post("sousuo.action", {json:strUser}, callbackFun, "json");
function callbackFun(json) {
alert("json");
}
}
目前只能返回对象名为jsonArray2的LIST对象,如果想同时返回jsonArray2以及对象名为second的字符串到onLoad方法里需要怎么做?
public String selcetUserInfo() throws Exception {
String second = "第2个参数";
JSONObject jsonObj = new JSONObject(json);
String name = jsonObj.getString("name");
int num = Integer.parseInt(jsonObj.getString("num"));
result = this.selcetUserInfo.selcetUserInfo(name, num);
getResponse().addHeader("Pragma", "no-cache");
getResponse().setCharacterEncoding("utf-8");
JSONArray jsonArray2 = JSONArray.fromObject(result);
getResponse().getWriter().write(jsonArray2.toString());
return null;
}
JS AJAX取返回参数方法为:
function onLoad() {
$.post("sousuo.action", {json:strUser}, callbackFun, "json");
function callbackFun(json) {
alert("json");
}
}
目前只能返回对象名为jsonArray2的LIST对象,如果想同时返回jsonArray2以及对象名为second的字符串到onLoad方法里需要怎么做?
解决方案 »
- 刚找到个实习JAVA程序员 感觉自己什么都不会了。。
- jsp中使用中文时出现乱码...
- 这个页面对应的ActionForm 写的不对,谁帮忙改改啊 急a~~~~大大们帮忙看下啊
- 大家帮忙给个思路
- 在JSP中如何限制时间查询条件,谢谢!
- 求正则表达式
- 如何把多条选上的复选框数据保存到数据库 在线等
- 求助
- 80分,这种网站技术如何处理,就是一个页面需要显示恨多小图片,点击小图片便展示真实的大图片
- 运行tomcat时报错:out of environment space,unable to set classpath dynamically.
- hibernate union查询的映射
- 爬虫heritrix 爬取一个特定页面,却没有把页面存下
list.put("second", "");
list.put("list", result);
JSONArray jsonArray2 = JSONArray.fromObject(list);
==json[0]
json[1]
然后jquery的$.ajax一下,得到json,然后data.name ,data.sex, data.age