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;
}
测试效果:
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;
}
测试效果:
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- JavaScript演示排序算法
- javascript实现10进制转为N进制数
- 最后一次说说闭包
- Ajax
- $.ajax()方法详解
- jQuery ajax - ajax() 方法
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法