weixin_33693070 2018-10-03 06:41 采纳率: 0%
浏览 53

仅自动刷新div ajax

I am trying to make auto-refresh every 5 second to div with ajax interval but, i missing something.

This is my div code:

<script>
    function loadlink(){
        $('#chart').load(function () {
            $(this).unwrap();
        });
    }

    loadlink(); // This will run on page load
    setInterval(function(){
        loadlink() // this will run after every 5 seconds
    }, 5000);

</script>
<div id="chart" >{!! $chart->script() !!}</div>

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33691700 2018-10-03 06:48
    关注

    your code is running u missing jquery file

      function loadlink() {
            console.log("called load link");
            $('#chart').load(function () {
                $(this).unwrap();
            });
        }
    
        loadlink(); // This will run on page load
        setInterval(function(){
            loadlink() // this will run after every 5 seconds
        }, 5000);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="chart" >{!! $chart->script() !!}</div>

    </div>
    
    评论

报告相同问题?