dongxikuo5171 2016-02-18 09:24
浏览 28

php通过ajax加载增加数量

I have a php loop with some php increasing numbers:

<loop start>
    <?php $num=0; $onum=0; ?>
    <div class="<?php echo ++num; ?>"></div>
    <div class="<?php echo ++onum; ?>"></div>
</loop end>

Now this loop is running to get posts on the page, but the posts on the other page is loaded to that same page with ajax and for that the number values are reset.

So instead of getting this:

<loop start>
    <div class="1"></div>
    <div class="2"></div>
</loop end>
<loop start>
    <div class="3"></div>
    <div class="4"></div>
</loop end>
<!-- ajax load -->
<loop start>
    <div class="5"></div>
    <div class="6"></div>
</loop end>

I'm getting this:

<loop start>
    <div class="1"></div>
    <div class="2"></div>
</loop end>
<loop start>
    <div class="3"></div>
    <div class="4"></div>
</loop end>
<!-- ajax load -->
<loop start>
    <div class="1"></div>
    <div class="2"></div>
</loop end>

Any ideas?

  • 写回答

3条回答 默认 最新

  • dozoqn3347 2016-02-18 09:36
    关注

    When you make your ajax call your PHP script has no idea what the current value is. So you need to send it with each (ajax) request.

    http://example.com/your-ajax-script.php?num=3&onum=4

    Then on the server side you'd get the values like so :

    $num = isset($_GET['num']) && !empty($_GET['num']) ? (int)$_GET['num'] : 0;
    $onum = isset($_GET['onum']) && !empty($_GET['onum']) ? (int)$_GET['onum'] : 0;
    
    // the reste of your code.
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端