ajax json
加载另一个程序jsonGene.jsp生成json数据的代码是:
function show(){ $.getJSON( "jsonGene.jsp", function(data){ $.each(data, function(index, values){ $.each(values, function(key, value){ $("#page").append(value + "<br>"); }); }); }); sHeight = 0; sTop = 0; }<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%><%@ page import="handle.DBlogic"%><%@ page import="handle.Seed"%><%@ page import="java.util.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title></title></head><body><% DBlogic dblogic = new DBlogic(); ArrayList<Seed> seedList = dblogic.getdata(); String str = "["; int i; for(i=0; i<seedList.size()-1; i++){ Seed seed = seedList.get(i); String temp = "{"; temp += "\"patternTypes\": " + '"' + seed.getPatternTypes() + '"' + ","; temp += "\"pattern1\": " + '"' + seed.getPattern1() + '"' + ","; temp += "\"label\": " + '"' + seed.getLabel()+ '"' + ","; temp += "\"value\": " + '"' + seed.getValue() + '"' + ","; temp += "\"anotherPattern1\": " + '"' + seed.getAnotherPattern1() + '"'; temp += "},"; str += temp; } Seed seed = seedList.get(i); String temp = "{"; temp += "\"patternTypes\": " + '"' + seed.getPatternTypes() + '"' + ","; temp += "\"pattern1\": " + '"' + seed.getPattern1() + '"' + ","; temp += "\"label\": " + '"' + seed.getLabel()+ '"' + ","; temp += "\"value\": " + '"' + seed.getValue() + '"' + ","; temp += "\"anotherPattern1\": " + '"' + seed.getAnotherPattern1() + '"'; temp += "}"; str += temp; str += "]"; out.print(str); %></body></html>