自动刷新DIV,没有PHP

时间:2013-02-25 19:31:16

标签: javascript ajax

我想在此页面上自动刷新div:http://americanart.si.edu/index_newsplash3r.cfm(“要探索的地方”区域)。现在我们有3个不同的图像和文本,当你重新加载页面时,任意显示。我希望这些元素能够自动更改,而无需重新加载页面。

该页面在Coldfusion 9中完成。大多数AJAX autorefresh代码假定您使用的是PHP。

有没有人可以在没有PHP的情况下使用我可以用来执行此操作的代码链接?我认为它不一定是Coldfusion代码。

感谢。

1 个答案:

答案 0 :(得分:0)

您可以设置对服务器端的Ajax调用以获取照片路径和文本。 这样的事情。

    $(function(){
        function FillDivAtRandom(current){
        setTimeout(function(){

            //pass the current place to explore id to the server so you don't get the same back, if none then return anyone.

            $.post("http://americanart.si.edu/Request/PlacesToExploreNext", current, function(data){

//fill the div with new data return from server
//you don't seem to have an ID on that div or elements so put one on it first then use it as a selector 

                //set the image
                $('#placestoexplore_image').attr('src', data.image);
                //set the text
                $('#placestoexplore_description').html(data.description);
            });

            //call the function again
            FillDivAtRandom(current);

        }, 10000);

        }
    }
相关问题