我在我的D3代码的信息的简单树结构。 D3的脚本呼吁从脚本d3.json()函数JSON和所产生的JSON是给树结构data.Now我有一对夫妇的信息将来自数据库,并击中了Servlet。 我必须使JSON动态地在Servlet,以便它可以在用户改变response.Here是脚本&我用JSON ..
这是从那里我做了一个Ajax调用Servlet的我的HTML文件。 阿贾克斯是调用Servlet中,但在取回响应错误。 我收到“发生错误”的message.When我运行servlet ......
function doajax(){
$.ajax({
url: "AccountServlet",
type: "post",
dataType: "json",
error:function(){
alert("error occured!!!");
},
success:function(data){
alert(data.fullName + "\n" + data.mobileNo);
}
});
}
这是我在哪里特林找回这个文件只是调用我得到一个错误occuree消息的响应Servlet.But响应中的HTML ...
IN的accountServlet我创造这样的JSON
ArrayList countList = new ArrayList();
countList.add(new DistinctSourceCount("Jan", 1800));
countList.add(new DistinctSourceCount("Feb", 1500));
countList.add(new DistinctSourceCount("March", 2000));
countList.add(new DistinctSourceCount("April", 1550));
countList.add(new DistinctSourceCount("May", 1000));
countList.add(new DistinctSourceCount("June", 1700));
countList.add(new DistinctSourceCount("July", 1400));
countList.add(new DistinctSourceCount("Aug", 1900));
countList.add(new DistinctSourceCount("Sept", 1000));
countList.add(new DistinctSourceCount("Oct", 1500));
countList.add(new DistinctSourceCount("Nov", 1100));
countList.add(new DistinctSourceCount("Dec", 2000));
Gson gson = new Gson();
JsonArray arrayObj = new JsonArray();
for (int i = 0; i < countList.size(); i++) {
DistinctSourceCount count = countList.get(i);
JsonElement linObj = gson.toJsonTree(count);
arrayObj.add(linObj);
}
JsonObject myObj = new JsonObject();
myObj.addProperty("success", true);
myObj.add("topList", arrayObj);
myObj.addProperty("totalCount", countList.size());
System.out.println(myObj.toString());
System.out.close();
这是我的代码,我已经这样做了far.Can谁能帮助我了解如何创建Servlet的JSON对象并获取回响应脚本?请任何人的帮助