2012-03-15 97 views
1

我目前正在使用jquery的ajax函数加载一个xml文件。目前,文件中的内容未在IE中加载或解析。我已经阅读了几个地方,我需要从我的xml中指定正确的响应标题,但是我不知道该怎么做,因为我发现的大多数示例都与通过php或其他语言生成的xml有关。我的ajax调用中的'dataType'现在是'html'。我不确定这是否是我需要更改的内容,或者是否需要更改我的xml文件中的某些内容,或者它们是否有所不同。我感谢任何帮助!我不知道,它可以帮助很多,但这里是我使用以检索XML文件的内容的代码:

$.ajax({ 
url: 'images/gallery-images/gallery-images.xml', 
dataType: "html", 
success: function(parseXML){ 

$(parseXML).find('section').each(function(){ 

    var $section = $(this), 
     photos = $section.find('photo'), 
     videos = $section.find('video'), 
     photoContainer = $('<div></div>', { id : $section.attr('id'), 'class' : 'gallery-section' }); 
    var videoContainer = $('<div></div>', { id : 'video-inner' }); 

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

    }); 

    videos.each(function(){ 

     var video = $(this).html(); 
     photoContainer.append(videoContainer); 
     videoContainer.append(video); 
    }); 
     $('#photo-viewer-inner').append(photoContainer); 
    }); 
} 
}); 

回答

1

正如你已经提到的,您dataType需求是"xml"。之后,你应该可以遍历所有浏览器中的xml而不会有任何问题只要xml有效

无效xml上的IE chokes比其他浏览器更频繁。

+0

我在验证我的XML。我会马上检查一下。 – jcbfshr 2012-03-15 19:31:02