xml jquery无法在Chrome

时间:2017-10-23 17:20:20

标签: xml

当我在Chrome中打开它时,由于某种原因它无法正常工作。有人能帮我吗 ?在IE工作精细!!!!我尝试在标题上使用简单的jquery并且工作。我找不到问题

    <script>
    $(document).ready(function () {
    $.ajax({
        type: "GET",
        type: "GET",
        url: "BatteriaXMLdata.xml",
        cache: false,
        dataType: "xml",
        success: function(xml) {
            $(xml).find('ProgressBAR').each(function(){
              var name = $(this).text();
              $(document.body).append('ProgressBAR: ' + name);
            });
        }
    });
});
</script>

完整代码:

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 

    $("div").css("border", "3px solid red");

});
</script>
</head>
<body>

<div id="progressbar">

<script >
$(document).ready(function () {
    $.ajax({
        type: "GET",
        type: "GET",
        url: "BatteriaXMLdata.xml",
        cache: false,
        dataType: "xml",
        success: function(xml) {
            $(xml).find('ProgressBAR').each(function(){
                        var name = $(this).text();

                $(document.body).append('ProgressBAR: ' + name);
            });
        }
    });
});
    </script>

</div>
</body>
</html>

P.S。 在头上jquery工作...

 $("div").css("border", "3px solid red");

我不知道我能做些什么...

1 个答案:

答案 0 :(得分:0)

由于下面的代码片段在Chrome中运行良好,我认为它肯定是XML格式问题:

&#13;
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){ 

    $("div").css("border", "3px solid red");

});
</script>
</head>
<body>

<div id="progressbar">

<script >
$(document).ready(function () {
    $('<?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don\'t forget me this weekend!</body><ProgressBAR>Test 1</ProgressBAR></note>').find('ProgressBAR').each(function(){
            var name = $(this).text();

        $(document.body).append('ProgressBAR: ' + name);
    });
});
    </script>

</div>
</body>
</html>
&#13;
&#13;
&#13;