【问题标题】:Jquery XML ie8 not working properlyJquery XML ie8 无法正常工作
【发布时间】:2013-05-21 00:55:10
【问题描述】:

我正在使用 jquery 1.6.2。我的 ie 控制台中显示的错误是 Unexpected call to method or property access。 jquery.min.js,第 17 行字符 29094。

我在所有现代浏览器上进行了测试,它在控制台上运行良好,没有任何错误,但是在尝试 ie8 时,我的 xml 文件没有加载。我的 ajax 调用是 OKAY,因为 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



}

【问题讨论】:

  • 可以用非缩小版替换jQuery脚本文件吗?这将使调试更容易。

标签: jquery xml internet-explorer-8


【解决方案1】:

另一种方法是首先让 IE8 理解 html5 元素,方法是将 Modernizr (http://modernizr.com/) 之类的内容添加到您的页面中。然后让其余的按照我们的预期运行。

【讨论】:

    【解决方案2】:

    问题出在附加代码上,我将部分用作容器。 ie8 可能不理解它,这就是为什么它不显示信息的原因,即使当你发出警报时它正确地显示了我的 xml 的内容......真是一团糟。怪异的 IE ... 这是我的解决方案,用一些类替换部分到 div。 教训:使用jquery更改dom时不要使用html5元素

    【讨论】:

      【解决方案3】:

      我在下面使用此代码,它对我有用。我在IE8、IE9、chrome、ff上测试完全没问题!

      // XML content look like this
      <root>
          <publish>
              <store>
                  <book title="How to fix IE"/>
                  <book title="...."/>
              </store>
          </publish>
      </root>
      
      
      // Build XML document
      var xDoc = $.parseXML(strXml);
      
      // create new child element using XML Document
      var xBook = xDoc.createElement("book");
      xBook.setAttribute("title", "How to fix bad ass IE!");
      // or you can using jquery
      $(xBook).attr("authr", "Bill ...");
      
      // Append child element to some where in XML Document
      var xStore = $(xDoc).find("store");
      xStore.append(xBook);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-01
        • 2010-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多