简体   繁体   English

尝试使用Javascript / Jquery解析XML文件时出现错误

[英]Error appears when trying to parse XML file using Javascript/Jquery

I am trying to parse an XML file using Javascript, but I keep getting the same error: 我正在尝试使用Javascript解析XML文件,但始终出现相同的错误:

SyntaxError: malformed hexadecimal character escape sequence
$.get('C:\Users\xxxxxx\Desktop\xmloutput.xml', function(xml) {

and it points to the single-quotes right before the C. I looked up the error, but there isn't much information about how to get around it. 它指向C之前的单引号。我查找了该错误,但是关于如何解决该错误的信息并不多。 Or is my syntax incorrect? 还是我的语法不正确? Here is my code: 这是我的代码:

$(document).ready(function(){
var data = new Array();

// Load the data from the XML file 
$.get('C:\Users\plk7504\Desktop\xmloutput.xml', function(xml) {

    // Split the lines
    var $xml = $(xml);

    // push series
    $xml.find('row').each(function(i, row) {

        var seriesOptions = {
            Category: $(series).find('Category').text(),
            Actual: $(series).find('Actual').text(),
            Plan: $(series).find('Plan').text(),
            Variance: $(series).find('Variance').text(),
        };

        // add it to the options
        data.push(seriesOptions);
    });
});
$("#month_an_plan1").replaceWith(data[0]);
});

update the path to be: 将路径更新为:

C:\\Users\\plk7504\\Desktop\\xmloutput.xml

Also see: How to open a local disk file with Javascript? 另请参阅: 如何使用Javascript打开本地磁盘文件?

Explanation: C:\\\\Users\\\\plk7504\\\\Desktop\\\\xmloutput.xml would be translated to C:\\Users\\plk7504\\Desktop\\xmloutput.xml right? 说明:C:\\\\ Users \\\\ plk7504 \\\\ Desktop \\\\ xmloutput.xml将转换为C:\\ Users \\ plk7504 \\ Desktop \\ xmloutput.xml对吗? so the problem you were seeing is because you were essentially trying to "escape" other characters such as '\\U' 所以您看到的问题是因为您实际上是在尝试“转义”其他字符,例如'\\ U'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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