首页 > 解决方案 > Why does AJAX (reload div every x time) not work?

问题描述

I want to reload a div every x time. This is what I have so far:

HTML:

 <div class="col-sm-6" id="myDesign" id="show">

          <h3>Show my cars:</h3>

          <?php $controller->getEvents(); ?>

</div>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

JS:

* ...In a document ready function... *

setInterval(function () {
        $('#show').reload()
    }, 3000); 

I think my reload function ist not correct at the "$('#show').reload()" line.

标签: javascriptphpjqueryhtmlajax

解决方案


You have to use the load function:

setInterval(function(){
   $('#show').load('/path/to/server/source');
}, 2000) /* time in milliseconds (ie 2 seconds)*/

推荐阅读