首页 > Web开发 > 详细

js解析后台传过来的json

时间:2014-12-16 14:42:59      阅读:290      评论:0      收藏:0      [点我收藏+]

 

java ,action
public void print(String rs){
		PrintWriter out;
		try {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType("text/plain");
			response.setCharacterEncoding("UTF-8");
			out = response.getWriter();
			// 获取分类数据
			out.print(rs);
			out.flush();
			out.close();
		} catch (IOException e) {
//			LogUtil.errorLog(TAG, "print", e);
		}
}

print("[{"proCode":"10241101","sellerId":"1001"},{"proCode":"10241101","sellerId":"1002"},{"proCode":"10241102","sellerId":"1001"}];")

  

后台拼成json格式,通过ajax接收返回结果,

$.ajax({
		url : "utilAction.action", 
		type : "GET", 
		data : "service=showProduct",
		success : function(result) {
			var products = eval(result);// 转换为json对象
			var datatable = "<table>";
			for ( var i in products) {
				datatable = datatable + "<tr><td>" + products[i].proCode + "</td><td>"
						+ products[i].sellerId+"</td></tr>";
			}
			datatable = datatable + "</table>";
			$("#mainDIV").html(datatable);

		}
	});

  

 

js解析后台传过来的json

原文:http://www.cnblogs.com/yaoqj/p/4166878.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!