首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

json返回的结果在页面加载的时候错误

2012-05-14 
json返回的结果在页面加载的时候异常数据库中有18条数据,通过hibernate查询转化成json返回到页面,然后通过

json返回的结果在页面加载的时候异常
数据库中有18条数据,通过hibernate查询转化成json返回到页面,然后通过js解析json数组。
从数据库查询开始我一步步的打印出来数据转化后的个数等情况一直都是18条记录,可是传到页面后数据变成了15条,这是为什么呢?
json数组如下:

HTML code
[{"content":"<p>&nbsp;sdfsdfasdf<\/p>","id":22,"author":"admin","title":"sdfd","c_id":"jiaoxue","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;sdfasd<\/p>","id":23,"author":"admin","title":"sdffg","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;ffghhjk<\/p>","id":24,"author":"admin","title":"sdfgg","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;khj<\/p>","id":25,"author":"admin","title":"jkl","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;ghjkghj<\/p>","id":26,"author":"admin","title":"jkhlk","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;ghjkghjk<\/p>","id":27,"author":"admin","title":"ghjgh","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;jkghjkghk<\/p>","id":28,"author":"admin","title":"ghkghjk","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;ghjkghjkghjk<\/p>","id":29,"author":"admin","title":"ghjk","c_id":"shixi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;ghjkghjkkghjk<\/p>","id":30,"author":"admin","title":"hgkgh","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;utryu<\/p>","id":34,"author":"admin","title":"tyu","c_id":"tongzhi","p_time":"2012-5-6","date":"2012-5-6"},{"content":"<p>&nbsp;123123123<\/p>","id":35,"author":"admin","title":"123","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;456<\/p>","id":36,"author":"admin","title":"456","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"","id":37,"author":"admin","title":"","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;qewrqewr<\/p>","id":38,"author":"admin","title":"qwerwqerw","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;e<\/p>","id":39,"author":"admin","title":"er","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;a<\/p>","id":40,"author":"admin","title":"a","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;sdfsdf<\/p>","id":41,"author":"admin","title":"adfg","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"},{"content":"<p>&nbsp;sd<\/p>","id":42,"author":"admin","title":"789","c_id":"tongzhi","p_time":"2012-5-7","date":"2012-5-7"}] 



页面代码:
JScript code
<script type="text/javascript">     var flag=0;    var title;    $.ajax({           url: "showNewsAction.do",           type:'jsonp',           async: false,           success: function(msg){            for(var i=0;i[color=#FF0000]<msg.toString().length[/color];i++){                 $("#shopping_list").append("<li><a href="+"/hcf/showNews.jsp?id="                     +msg.news[i].id                     +">"                     +i                     +msg.news[i].id                     +msg.news[i].c_id                     +msg.news[i].title                     +msg.news[i].author                     +msg.news[i].date.toString()                     +"</a>"+"--------"                     +"<a href=delNewsAction.do?id="+msg.news[i].id+">删除</a>"                     +"</li>"                     );             }            }    });</script>


[解决办法]
for(var i=0;i<msg.length;i++){
$("#shopping_list").append("<li><a href="+"/hcf/showNews.jsp?id="
+msg[i].id
+">"
+i
+msg[i].id
+msg[i].c_id
+msg[i].title
+msg[i].author
+msg[i].date.toString()
+"</a>"+"--------"
+"<a href=delNewsAction.do?id="+msg[i].id+">删除</a>"
+"</li>"
);








news 哪来的?


楼主试试
[解决办法]
你确定:showNewsAction.do执行后是18条记录吗?

热点排行