helloxielan 2014-08-28 09:42 采纳率: 0%
浏览 137

如何重新加载div

I have a little problem with reloading div content. I have a form which is split in 4 steps. On the second step people are able to add items (giftcards or checks) When someone adds a new item this item is added to an array which is stored in a session. After adding the item I would like to show the item to the customer so I wanted to refresh / reload the div with the PHP function that shows the data.

<div class="kosten" id="kosten">
                <?php
                    if($session->exists('stap2')) {
                        echo $lijst->output();
                    }
                ?>
</div>

The function exists is to check if a sessions has been set. The function output is a function to output html with session data.

So what have I tried so far: First I tried to do something like:

$('#kosten').load('index.php');

This however resulted in showing me the index.php but I was back at step 1. I also tried to add some JavaScript / jQuery to show step 2 again but this also didn't help

Second thing I tried:

setInterval(function() {
                    $('#kosten').text();
                }, 3000);

Which resulted in showing me a half blank page. It wouldn't reload the bottom half of the page. And with an interval you will also see that the div is being reloaded.

Third thing I have tried is to do another post to PHP. It would than echo $lijst->output() as a return. But this gave me an array instead of html

So what I would like to do is reload the div so not the page after a button of "add item" is clicked. Is there any other way of doing this?

Thanks in advance

  • 写回答

3条回答 默认 最新

  • weixin_33701617 2014-08-28 09:45
    关注

    jQuery has the option of adding a selector to do what you look for:

    $('#kosten').load('index.php #kosten');
    
    评论
  • 普通网友 2014-08-28 09:56
    关注

    I don't know what index.php contains, but you can try to add index.php page url instead of 'index.php' only.

    $('#kosten').load('url of index.php');
    
    评论
  • weixin_33728268 2014-08-29 07:09
    关注

    I solved my problem with adding another $.post. There I echoed the required function

    echo $lijst->output();
    

    After that I could use that as the answer of the function which I then could use for

    $('.kosten').html(answer);
    

    Doing this solved my problem.

    评论

报告相同问题?

悬赏问题

  • ¥80 关于海信电视聚好看安装应用的问题
  • ¥15 vue引入sdk后的回调问题
  • ¥15 求一个智能家居控制的代码
  • ¥15 ad软件 pcb布线pcb规则约束编辑器where the object matpcb布线pcb规则约束编辑器where the object matchs怎么没有+15v只有no net
  • ¥15 虚拟机vmnet8 nat模式可以ping通主机,主机也能ping通虚拟机,但是vmnet8一直未识别怎么解决,其次诊断结果就是默认网关不可用
  • ¥20 求各位能用我能理解的话回答超级简单的一些问题
  • ¥15 yolov5双目识别输出坐标代码报错
  • ¥15 这个代码有什么语法错误
  • ¥15 给予STM32按键中断与串口通信
  • ¥15 使用QT实现can通信