Jquery XML ie8 无法正常工作

标签 jquery xml internet-explorer-8

我使用的是 jquery 1.6.2。我的 ie 控制台中显示的错误是意外调用方法或属性访问。 jquery.min.js,第 17 行字符 29094。

我在所有现代浏览器上进行了测试,它在控制台上运行完美,没有任何错误,但是在 ie8 上尝试时,我的 xml 文件未加载。我的 ajax 调用没问题,因为 selectXml 可以运行,但里面的代码不行(它应该不会有任何问题,因为它在其他浏览器上工作,而且我已经做了 XML 验证),已经挣扎了几个小时。我认为 ie8 不能与 jquery 正常工作。

$(document).ready(function() {  
 $.ajax({
    type: "GET",
    url: "menu.xml",
    dataType:"text",
    success: selectXml
});

(我的 selectXml 函数)

function selectXml (xml) {

    var xmlDoc = $.parseXML(xml);
    console.log(xmlDoc);
    var i = 0,
    j = 0,
    k = 0,
    l = 0,  
    maxCat = $(xmlDoc).find("categorie").length,
    maxPage = 14,
    numPlate = 0,
    numSection = 2,
    page = 0,
    queryXml,
    title,
    theNo, 
    thePlate,
    thePrice,  
    theSection;

    //for each page divide it in 2 sections
    for(i=1; i<=maxPage; i++){
        if( j < maxCat){
        //for each sections add the title and left, right section

            //for each left right section, fill up the dishes
            for(k=0; k<numSection; k++){

                queryXml = $(xmlDoc).find('categorie').eq(j);


                title = queryXml.find("title[lang=" + jQuery.fn.language + "]").text();
                numPlate = queryXml.find('plate').length;
                $('#menu'+ i).append('<section></section>');
                $('section').eq(j).append('<div class="menuTitle"><h1>'+ title +'</h1><div class="ribbon"></div></div><div class="menuLeft"><ul></ul></div><div class="menuRight"><ul></ul></div>');
                theSection = $('section').eq(j);

                for(l=0; l<numPlate; l++){
                    if(l< (numPlate/2)){
                        theNo = queryXml.find('plate').eq(l).find('number').text();
                        thePrice = queryXml.find('plate').eq(l).find('price').text();
                        thePlate = queryXml.find('plate').eq(l).find('description[lang='+jQuery.fn.language+']').text();
                        //console.log(thePlate);
                        $('section').eq(j).find('.menuLeft ul').append('<li><span class="itemNumber">' + theNo +'</span><span class="itemName">'+ thePlate+'</span> <span class="itemPrice">'+ thePrice+'</span></li>');


                    }
                    else {
                        theNo = queryXml.find('plate').eq(l).find('number').text();
                        thePrice = queryXml.find('plate').eq(l).find('price').text();
                        thePlate = queryXml.find('plate').eq(l).find('description[lang='+jQuery.fn.language+']').text();
                        $('section').eq(j).find('.menuRight ul').append('<li><span class="itemNumber">' + theNo +'</span><span class="itemName">'+ thePlate+'</span> <span class="itemPrice">'+ thePrice+'</span></li>');
                    }


                };


                    numPlate = $(this).find('plate').length;

                j++;

            }

        }//end if
    }//end for



}

最佳答案

另一种方法是首先通过在页面中包含 Modernizr ( http://modernizr.com/ ) 等内容来让 IE8 理解 html5 元素。然后让其余部分按我们的预期运行。

关于Jquery XML ie8 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8238246/

相关文章:

javascript - 在 javascript 或 jquery 中选择第一个后如何修复另一个下拉值?

css - IE7 和 IE8 的最后一个 child 和第 n 个 child

javascript - 如何在不刷新页面的情况下使用codeigniter中的websocket更新内容

javascript - dropdownlistfor 无法使用 jquery 从 Controller 更改为选定值

ios - NSXMLParser\n 和\t 文本内部

python - 使用 elementTree 编辑和复制 xml block

css - DIV 在 IE8 中重复

css - 在 IE8 中强制显示垂直滚动条

jquery - 设置一个 DIV 高度等于另一个 DIV 的高度

SQL获取XML的叶节点