Разбор XML с помощью jQuery - PullRequest
1 голос
/ 10 декабря 2010

Хорошо, поэтому я могу проанализировать XML с помощью jQuery, но, похоже, он работает только в FireFox, а не в IE.

Мой файл XML:

<?xml version="1.0" encoding="utf-8" ?>
<Answers>
    <Question>
        <question-title>Question One - Title</question-title>
        <a>24</a>
        <b>36</b>
        <c>10</c>
        <d>30</d>
    </Question>
</Answers>

Мой код, который анализирует XML:

var xmlType = 'xml';
        if ($.browser.msie) {
            xmlType = 'text/xml'
        }
$.ajax({
            type: "GET",
            url: "answers.xml",
            dataType: xmlType,
            success: function(xml) { //if the XML exists
                $(xml).find('Answers').each(function(){ //go inside answers
                    $(this).find('Question').each(function(){ //for each question...
                        var moo = $(this).find('question-title').text();
                        $('.question-title').append(moo); //append the question title

                        var a = $(this).find('a').text();
                        var b = $(this).find('b').text();
                        var c = $(this).find('c').text();
                        var d = $(this).find('d').text();

                        $('.label1').html(a+'%');
                        $('.label2').html(b+'%');
                        $('.label3').html(c+'%');
                        $('.label4').html(d+'%');

                        $('.input1').val(a);
                        $('.input2').val(b);
                        $('.input3').val(c);
                        $('.input4').val(d);

                        $('.cu-mid','.cuboid.'+'green1').animate({
                            height: a
                        }, 550);
                        $('.cu-mid','.cuboid.'+'green2').animate({
                            height: b
                        }, 550);
                        $('.cu-mid','.cuboid.'+'green3').animate({
                            height: c
                        }, 550);
                        $('.cu-mid','.cuboid.'+'green4').animate({
                            height: d
                        }, 550, function() {

                            $('.cu-mid').animate({
                                height: '+='+50
                            }, 550);

                        });
                    });
                });
            }
        });

Вывод в FireFox является правильным - высота над необходимыми элементами.Но в IE - ничего ... zip ... nada ...

Сначала я подумал, что это может быть dataType, поэтому я добавил оператор if ... Это непомогите либо.

Есть идеи, умные тела?!

Приветствия.

edit : Я получаю следующие ошибки в IE:Неверная строка аргумента 66 - конечная скобка в: $(xml).find('Answers').each(function(){Объект ожидаемой строки 1 - ???

Ответы [ 2 ]

1 голос
/ 10 декабря 2010

Неважно, я понял:

function runQuiz(whichQ) {
            if (window.XMLHttpRequest) { 
                xmlhttp = new XMLHttpRequest(); 
            } else { 
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            xmlhttp.open("GET", whichQ, false); 
            xmlhttp.send(); 
            xmlDoc = xmlhttp.responseXML; 

            var a = xmlDoc.getElementsByTagName("a");
            var a2 = $(a).text();
            var b = xmlDoc.getElementsByTagName("b");
            var b2 = $(b).text();
            var c = xmlDoc.getElementsByTagName("c");
            var c2 = $(c).text();
            var d = xmlDoc.getElementsByTagName("d");
            var d2 = $(d).text();

            $('.label').fadeOut(350);
            $('.cu-mid','.cuboid.'+'green1').animate({ height: a2   }, 550);
            $('.cu-mid','.cuboid.'+'green2').animate({ height: b2   }, 550);
            $('.cu-mid','.cuboid.'+'green3').animate({ height: c2   }, 550);
            $('.cu-mid','.cuboid.'+'green4').animate({ height: d2   }, 550, function() {
                $('.cu-mid').animate({
                    height: '+='+50
                }, 550, function() {
                    $('.label1').html(a2+'%');
                    $('.label2').html(b2+'%');
                    $('.label3').html(c2+'%');
                    $('.label4').html(d2+'%');
                    $('.label').fadeIn(350);
                }); 
            });
        }

$(document).ready(function() {
   runQuiz('question1.xml');
});
0 голосов
/ 10 декабря 2010

Существуют различия в том, как наилучшим образом получить объект xmlHttpRequest в версиях Internet Explorer.

См. Примечания MSDN по Объект XMLHttpRequest

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...