0
我一直在尋找高和低在互聯網上爲這個問題的答案,我認爲有一些我失蹤。我正在通過jquery $ .ajax()從xml文檔中的照片庫中讀取數據,而我在使用IE7時遇到了問題。我使用的功能在我測試過的所有其他瀏覽器中都能正常工作。
我已經讀了很多關於爲IE設置正確的dataType和contentType的信息,但我開始懷疑這是否是問題所在。我已經嘗試了不同dataTypes和contentTypes的大量組合,並且它們都沒有成功。我想知道是否可能存在與我的xml或我的函數讀取xml的方式有關的問題,因爲通過函數設置當前的方式,所有內容都在IE7中運行,但沒有任何圖像添加到DOM 。
var dataType;
if ($.browser.msie) { dataType = 'text' } else { dataType = 'html' };
$.ajax({
type: 'GET',
url: 'images/gallery-images/gallery-images.xml',
dataType: dataType,
success: function(parseXML){
$(parseXML).find('section').each(function(){
var $section = $(this),
photos = $section.find('photo'),
photoContainer = $('<div></div>', { id : $section.attr('id'), 'class' : 'gallery-section' });
photos.each(function(){
var photo = $(this),
imageurl = photo.attr('imageurl'),
title = photo.find('title').text(),
description = photo.find('description').html(),
kind = photo.find('description').attr('type');
icon = photo.find('icon').attr('source');
iconClass = photo.find('icon').attr('class');
var photoWrapper = $('<div class="photo"></div>'),
imageElem = $('<img />', { 'src' : imageurl, 'class' : 'gallery-photo' }),
photoInfo = $('<div></div>', { 'class' : 'photo-info ' + kind }),
iconInsert = $('<img />', { 'src' : icon, 'class' : iconClass }),
header = $('<h1></h1>', { text: title }),
photoDescription = $('<div></div>', { html: description });
photoInfo.append(iconInsert).append(header).append(photoDescription);
photoWrapper.append(imageElem).append(photoInfo);
photoContainer.append(photoWrapper);
});
$('#photo-viewer-inner').append(photoContainer);
});
var videos = '<div id="videos"></div>';
$('#photo-viewer-inner').append(videos);
$('#videos').load('images/gallery-images/videos.html #video-inner');
這就是我用來從我的XML中提取數據的代碼。就像我說的那樣,包括這個和所有東西在內的所有東西似乎在IE7中運行良好,但圖像從未加載過。
我很難過,希望能在這裏找到一些幫助。
是html源代碼中的圖片標籤? – kclair 2012-03-16 20:43:58
去做你自己的調試。使用腳本控制檯,或者如果你不能這樣做,可以用'alert()'來看看代碼實際上做了些什麼。最值得注意的是,在ajax調用中捕獲異常可以爲您提供有趣的見解。 – tdammers 2012-03-16 20:44:25
它的作品適用於其他瀏覽器嗎? IE7很糟糕。我不知道它是否會幫助你,但大約一年前的一次,我的ajax不能在IE7中工作,因爲我使用的是粗體標記而不是強壯的標記。不知道爲什麼這打破了它,但只是一個建議。 – Rooster 2012-03-16 20:47:52