dongmeng2509 2012-12-14 12:19
浏览 75
已采纳

使用codeigniter,ajax如何从数组中获取下一条记录

I have an array

http://www.postano.com/api/posts.php?ak=XXXX&ts=XXXXX&sig=XXXXX&postano=12345&start=0&count=20

I will be fetch first 20 records initially. Here is the class

class social extends CI_Controller{
function data()
{
$start = $k;

$resultjson = $this->curl->simple_get("http://www.postano.com/api/posts.php?ak=XXXXX&ts=XXXXX&sig=XXXXX&postano=12345&start=$k&count=20");
$resultant_data = json_decode($resultjson,true);
foreach ($resultant_data as $key => $value)
     {
     //print_r($value);
     $this->load->view('feeds',$value);
     }
 }

}

Here feeds is my view.

How can i fetch next 20 records say start or $k = 20 so that I can display the results from 0-20 then 21-40 and so on...

I am trying to implement an autoload or loadmore functionality. I am not using model(database) the only source is json response

  • 写回答

2条回答 默认 最新

  • dongluan5740 2012-12-14 13:48
    关注

    Since you mentioned over chat that you want to use AJAX, on page load have the first request you wanted. Load up your 20 results.

    When you want more results, send an AJAX request and from the script that got requested curl request more products from a specified starting point and limit like Havelock mentioned, something along the lines of

    http://www.postano.com/api/posts.php?ak=XXXX&ts=XXXXX&sig=XXXXX&postano=12345&s‌​tart=21&count=20
    

    Then return the results you got form your ajax request and append it to the page if you want to keep the first 20 results that you had from page load, otherwise replace it.

    Good luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于 S7-PLCSIM Advanced 5.0本地TCP连接无法读写数据
  • ¥15 关于温度改变石墨烯介电性能(关键词-介电常数)
  • ¥150 HDMI分路器LT86102 的输出在890MHz频点处EMC超标8DB
  • ¥15 druid(相关搜索:数据库|防火墙)
  • ¥15 大一python作业
  • ¥15 preLaunchTask"C/C++: aarch64- apple-darwin22-g++-14 生成活动 文件”已终止,退出代码为-1。
  • ¥60 如何鉴定微信小程序数据被篡改过
  • ¥18 关于#贝叶斯概率#的问题:这篇文章中利用em算法求出了对数似然值作为概率表参数,然后进行概率表计算,这个概率表是怎样计算的呀
  • ¥20 C#上传XML格式数据
  • ¥15 elementui上传结合oss接口断点续传,现在只差停止上传和继续上传,各大精英看下