我有問題的實施谷歌幻燈片(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>
當混合分離JS庫這樣的事情時,可能會出現很多錯誤,你可以發佈你用來包含上面的代碼嗎?這可能有助於縮小範圍。 – 2009-10-24 20:04:41
我用一個完整的例子編輯了主文章。謝謝! – ufk 2009-10-24 20:24:30