我在我的MVC3-Webseite中有圖片,他們必須每30秒更新一次。因爲圖像每30秒更新一次im服務器。所以我試圖用JQuery來更新它:我如何更新我的MVC 3網站中的圖像?
<div id="galerie">
<ul>
<li>
<img id = "img1" class = "img1" alt="Image 7" src="@Url.Content("Content/Images/Image_7.jpg")"/>
Image 7
</li>
<li>
<img id = "img2" class = "img2" alt="Image 5" src="@Url.Content("Content/Images/Image_5.jpg")"/>
Image 5
</li>
</div>
<script type="text/javascript">
function UpdateImages() {
$.get('@Url.Action("Details","Display", new { id = "test" })', function (data) {
$('#main').replaceWith(data);
});
}
function myFunction() {
setInterval(UpdateImages, 30000);
}
</script>
但是問題是圖像沒有被更新。他們需要再次Pageload。不是嗎? 所以我想知道我怎麼能用JS解決Pageload事件?或者是否有解決問題的其他解決方案? 謝謝
MarekBurkut
你在獲得什麼數據?以及你如何在這個數據中的圖像網址? –
我得到整個網站的正確內容。所以我把它替換爲「$('#main')。replaceWith(data);」適當的頁面片段。圖片網址不會更改。它們總是一樣的。這意味着URL永遠不會改變。圖像內容只有更改。 – burkut