2009-10-24 24 views
0

我有問題的實施谷歌幻燈片(http://www.google.com/uds/solutions/slideshow/index.html)通過使用jquery load()函數加載我的web應用程序。谷歌幻燈片顯示從ajax呼叫時出現空白屏幕

的index.html:

<script type="text/javascript" src="jquery-1.3.2.js"></script> 
<div id="moshe"></div> 

<script type="text/javascript"> 

$(document).ready(function(){ 
$('#moshe').load('test.html'); 
}); 

</script> 

的test.html:

<script type="text/javascript"> 
function load() { 
    var samples = "http://dlc0421.googlepages.com/gfss.rss"; 
    var options = { 
    displayTime: 2000, 
    transistionTime: 600, 
    linkTarget : google.feeds.LINK_TARGET_BLANK 
    }; 
    new GFslideShow(samples, "slideshow", options); 

} 
google.load("feeds", "1"); 
google.setOnLoadCallback(load); 
</script> 
<div id="slideshow" class="gslideshow" style="width:300px;height:300px;position:relative; border: 2px solid blue">Loading...</div> 

當我執行的test.html,它加載幻燈片就好了。當我嘗試加載使用index.html實際上調用jquery的$ .load()函數加載test.html的內容到一個特定的div元素時,我看到畫廊正在加載該div,但是當它即將顯示圖像整個頁面清除,我擁有的只是一個空白頁面。

任何想法?


不同版本的index.html不使用jQuery:

<script type="text/javascript"> 
    function makeRequest(url) { 
     var httpRequest; 

     if (window.XMLHttpRequest) { // Mozilla, Safari, ... 
      httpRequest = new XMLHttpRequest(); 
      if (httpRequest.overrideMimeType) { 
       httpRequest.overrideMimeType('text/xml'); 
       // See note below about this line 
      } 
     } 
     else if (window.ActiveXObject) { // IE 
      try { 
       httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
      } 
      catch (e) { 
       try { 
        httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
       } 
      catch (e) {} 
     } 
     } 

     if (!httpRequest) { 
     alert('Giving up :(Cannot create an XMLHTTP instance'); 
     return false; 
     } 
     httpRequest.onreadystatechange = function() { alertContents(httpRequest); }; 
     httpRequest.open('GET', url, true); 
    httpRequest.send(''); 

    } 

function alertContents(httpRequest) { 

    if (httpRequest.readyState == 4) { 
     if (httpRequest.status == 200) { 
      document.getElementById('moshe').innerHTML=httpRequest.responseText; 
     } else { 
      alert('There was a problem with the request.'); 
      } 
     } 

    } 
makeRequest('test.html'); 
</script> 
+0

當混合分離JS庫這樣的事情時,可能會出現很多錯誤,你可以發佈你用來包含上面的代碼嗎?這可能有助於縮小範圍。 – 2009-10-24 20:04:41

+0

我用一個完整的例子編輯了主文章。謝謝! – ufk 2009-10-24 20:24:30

回答

0

嘗試把

$('#moshe').load('test.html'); 

$(document).ready(function(){ 
    $('#moshe').load('test.html'); 
}); 

另外,我不知道,如果你複製或鍵入這一點,但你必須

<script style="text/javascript"> 

當你想

<script type="text/javascript"> 

我個人使用:

<script language="javascript"> 

但我不確定哪個是最好的。

+0

感謝您的幫助,不幸的是,固定的腳本產生了相同的結果。 – ufk 2009-10-25 09:10:32

+0

如果你調用你的加載函數別的東西。也許這是干擾別的稱爲負載? – 2009-10-28 14:00:00

+0

我添加了另一個代碼示例,但沒有使用jquery,結果有點不同。現在,而不是一個空白的屏幕,我看到「正在加載...」,但不是實際的畫廊,但 – ufk 2009-11-08 17:23:39