开发者

jQuery load with auto-refresh, passing variables in order

I have the following jquery code:

$(".rotateNews").load("/load_news.php");
    var refreshId = setInterval(function() {
        $(".rotateNews").load('/load_news.php?newsID=');
    }, 5000);

This refreshes a div with the class rotateNews with load_news.php every 5 seconds. load_news.php pulls a random news article from a MySQL database. I need a way to track the previously 开发者_JS百科loaded news article and pass it back to this function (or pass it back to load_news.php, which is the ultimate goal). Is there anyway to do this?


Try this:

In the output of your load_news.php, declare a script section and populate a variable with the news id:

<script type=text/javascript>
var oldNewsID = 1;
</script>

Then your setInterval would look like this:

var refreshId = setInterval(function() {  
    $(".rotateNews").load('/load_news.php?newsID=' + oldNewsID);  
}, 5000);  

Let me know if that doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜