您的位置:首页 > Web前端 > JavaScript

ajax从后台向前台传数组

2016-04-14 13:57 507 查看
也是网上搜半天没搜到,最后自己整出来了

js部分:

$.ajax({
dataType : "json",
type : "POST",
url : "getPathMap",
success : function(data) {
var points = eval(data);
alert(points[1][0]+points[1][1]);
},
error : function(e, type, msg) {
alert(type + "===" + msg);
}
});

java部分:
public String getPathMap(HttpServletRequest request, HttpServletResponse response) {
PointsInfo pointsInfo = new PointsInfo();

try {
/*** 根据条件取值生成二维数据,并转成json ***/
// JSONArray jsonArray =
// JSONArray.fromObject(pointsInfo.getPointLine(" or id < '20' "));

String[][] aaa = { { "xxxx", "oooo" }, { "fu", "ck" } };
JSONArray jsonArray = JSONArray.fromObject(aaa);

response.setContentType("text/html;charset=UTF-8");
response.setContentType("application/json");
PrintWriter pw = response.getWriter();
pw.print(jsonArray); // 轨迹图条件,取少量数据
pw.flush();
pw.close();
} catch (IOException e1) {
e1.printStackTrace();
}

return null;
}

测试效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ajax javascript