简体   繁体   中英

jQuery IE6 stripping HTML from XML.

I have a problem with IE6 that is stripping HTML from XML even after I wrap this inside CDATA

eg <name>Product <![CDATA[<br />]]> Name</name>

var phoneCarousel = $("#phone-carousel"), phoneXmlPath = "deals/phones.xml";

    // Generate to allow image to be vertial aligned bottom. 
    function generateTable(name, image){
        var table = '<table cellspacing="0" cellpadding="0">';
        table += '<tr><td class="img"><img alt="'+name+'" src="'+image+'"></td></tr>';
        table += '<tr><td>'+name+'</td></tr>';
        table += '</table>';
        return table;
    }

    phoneCarousel.addClass("loading");

    // Get Phones XML
    $.ajax({
        type: "GET",
        url: phoneXmlPath,
        dataType: "xml",
        contentType: "application/xml; charset=utf-8",
        success: function(xml){

            phoneCarousel.html("");

            //This function will loop for each match on phones/phone
            $(xml).find("phone").each(function(index, value){
                var tis = $(this), first = '';
                if(index == 0){
                    first = ' class="selected"';
                }
                phoneCarousel.append('<li'+first+'>' + generateTable(tis.find("name").text(), tis.find("thumbnail").text()) + '</li>');
            });  

            phoneCarousel.removeClass("loading");
        },
        error:function(xhr,type){
            if(type == null){
                var errorMsg = "There was an error loading the phone.xml file!<br/>Please make sure the path to the xml file <strong>'"+phoneXmlPath+"'</strong> is correct.";
            }else if(type == "parsererror"){
                var errorMsg = "There is an error in the file <strong>'"+phoneXmlPath+"'</strong>.";
            }else{
                var errorMsg = "An error has been detected.";
            }       
            phoneCarousel.removeClass("loading").html("<p><strong>Error:</strong> "+errorMsg+"</p><p><strong>Type of error:</strong> "+type+".</p>");       
        }           
    });

尝试使用text/xml而不是application/xml作为内容类型,IE对内容类型非常严格。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM