为什么点完按钮它没动静啊,一点内容它也不肯显示啊?有解析JSON的成功案例还望给我发几个参考,忘各位大侠赐教,谢谢!<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/html4/strict.dtd ">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Json Document</title>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function(){
$("#button1").click(function(){
$.getJSON('b.json',function(data){
$("#json").empty();
$.each(data,function(entryIndex,entry){
var html="<div class= entry >";
html += "<h3 class= term >"+entry[term]+ "</h3>" ;
html += "<div class= part >"+entry[ part ]+"</div>";
html += "<div class= definition >"+entry[ definition ];
if(entry[ quote ]){
html+="<div class= quote >";
$.each(entry[ quote ],function(quoteIndex,line){
html+="<p>"+line+"</p>";
});
html+="</div>";
}
html+="</div>";
html +="</div>";
$("#json").after(html);
});
});
});
});
</script>
</head>
<body>
<button id="button1"><b>Get Json Document</b></button>
<div id="json" >hghghghg</div>
</body>
</html>以下是b.json文件内容:
[
{
"term":"BACCHUS",
"part":"n.",
"definition":"A convenient deity invented by the ancients as an excuse for getting drunk.",
"quote":[
"Is public worship,then,a sin.",
"That for devotions paid to Bacchus",
"The lictors dare to run us in.",
"And resolutely thump and whack us?"
],
"author":"Jorace"
},
{
"term":"BACKBITE",
"part":"v.t.",
"definition":"To speak of a man as you find him when he can t find you."
},
{
"term":"BEARD",
"part":"n.",
"definition":"The hair that is commonly cut off by those who justly execrate the absurd Chinese custom of shaving the bead."
}
]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Json Document</title>
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript">
$(function(){
$("#button1").click(function(){
$.getJSON('b.json',function(data){
$("#json").empty();
$.each(data,function(entryIndex,entry){
var html="<div class= entry >";
html += "<h3 class= term >"+entry[term]+ "</h3>" ;
html += "<div class= part >"+entry[ part ]+"</div>";
html += "<div class= definition >"+entry[ definition ];
if(entry[ quote ]){
html+="<div class= quote >";
$.each(entry[ quote ],function(quoteIndex,line){
html+="<p>"+line+"</p>";
});
html+="</div>";
}
html+="</div>";
html +="</div>";
$("#json").after(html);
});
});
});
});
</script>
</head>
<body>
<button id="button1"><b>Get Json Document</b></button>
<div id="json" >hghghghg</div>
</body>
</html>以下是b.json文件内容:
[
{
"term":"BACCHUS",
"part":"n.",
"definition":"A convenient deity invented by the ancients as an excuse for getting drunk.",
"quote":[
"Is public worship,then,a sin.",
"That for devotions paid to Bacchus",
"The lictors dare to run us in.",
"And resolutely thump and whack us?"
],
"author":"Jorace"
},
{
"term":"BACKBITE",
"part":"v.t.",
"definition":"To speak of a man as you find him when he can t find you."
},
{
"term":"BEARD",
"part":"n.",
"definition":"The hair that is commonly cut off by those who justly execrate the absurd Chinese custom of shaving the bead."
}
]
解决方案 »
- spring与hibernate整合报错
- 我这个项目dao层怎么设计
- 初学JSP遇到的简单问题
- java io 类中 操作文件
- 请高手指点 在 网站用session 于 cookies 疑惑?主要是为了解决网站速度问题 !大家来讨论一下。
- 我想下载tomcat,配置开发环境,但是到了官方主页上却怎么也找不到,我是新手,帮帮我吧!
- 为什么我的弹出框总在页面后面!
- 请教图片服务器上传问题
- 如何在editplus中写jsp程序时让它高亮显示?
- 要开发unix下的jsp程序,请大家进来讨论一下。
- 求救:华为包开发SGIP。节点编码是3*********,长度超出范围
- 请教一个ec table导出excel的问题
在$.getJSON('b.json',function(data){ 下面也加个alert语句,看data是什么形式的。
我的例子:返回来的数据如下,要把他们插到表格里面的话
[[null,"成都市青羊区北大街19号---"],[null,"成都市青羊区北大街19号---"],[null,"成都市青羊区北大街19号---"]]
$.each(data, function(k, v) {
tbody+="<tr>";
$.each(v,function(kk, vv) {
tbody+="<td>"+vv+"</td>";
});
tbody+="</tr>";
});
希望对你有用哦