2013-02-25 57 views
0

我想在此頁面自動刷新一個div:http://americanart.si.edu/index_newsplash3r.cfm(「探索地點」區域)。現在我們有3個不同的圖像和文字,當您重新加載頁面時,它們會任意顯示。我希望這些元素能夠自動更改,而無需重新加載頁面。Autorefresh DIV,No PHP

該頁面在Coldfusion 9中完成。大多數AJAX autorefresh代碼假設您使用的是PHP。

有沒有人有鏈接到我可以用來做到這一點沒有PHP的代碼?我認爲它不一定是Coldfusion代碼。

謝謝。

回答

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); 

     } 
    } 
+0

讓我試試看。謝謝。我會讓你知道結果如何。 – outtacontext 2013-02-25 21:03:32

+0

幾個問題blackops:這個網址應該是什麼:'//傳遞當前位置到服務器上探索id,所以如果沒有返回任何人,就不會返回相同的結果。 $ .post(「http://americanart.si.edu/Request/PlacesToExploreNext」,current,function(data){'另外,我確實有一個關於該Div的類,但我可以將其更改爲一個ID。 – outtacontext 2013-02-25 21:36:18

+0

url是一個服務器端文件,它將從HTTP post獲取變量,然後返回一個包含圖像源和描述的json對象。 – blackops 2013-02-28 16:21:57