weixin_33698823 2012-12-04 19:26 采纳率: 0%
浏览 49

JSON Javascript Onclick加载程序

I have a little script reading out a JSON feed and writing it down in HTML. Now I want my scirpt to only show 5 elements and load the next 5 elements with an forward button or to show the last 5 with a backward button Is there any possility to do that? Just give me a few pointers, where I could start my research for building a function like that.

My code till now, just to show you guys :

<script type="text/javascript">
$(function()
{
$(document).ready(function()
{
$.getJSON("json_data2.php",function(data)
{
$.each(data.posts, function(i,data)
{
var div_data =
"<div ><a href='"+data.url+"'>"+data.title+"</a></div>";
$(div_data).appendTo("#test");
});
}
);
return false;
});
});
</script>

<div id="test"></div>
  • 写回答

1条回答 默认 最新

  • weixin_33739646 2012-12-06 00:10
    关注

    Sounds like you're trying to implement pagination. Generally this is best done on the server side. In your case this would be json_data2.php. You could have json_data2.php read 2 query strings called for example startPosition and amount. So startPosition can offset the list of items based on the number passed. Then amount would tell the json_data2.php how many items to return. Then each time next or previous is clicked the startPosition would be incremented or decremented.

    So

    json_data2.php?startPosition=0&amount=5 would return the first 5 results

    Then

    json_data2.php?startPositon=5&amount=5 would return the next 5 results.

    评论

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮