jquery $ .ajax()调用和IE

时间:2012-03-15 19:10:57

标签: jquery xml ajax internet-explorer

我目前正在使用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 个答案:

答案 0 :(得分:1)

正如您已经提到的,您的dataType必须是"xml"。之后,只要xml有效 ,您就应该能够在所有浏览器中遍历xml而不会出现 问题。

IE对无效xml的阻塞比其他浏览器更频繁。