简体   繁体   中英

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:

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. 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?

Explanation: C:\\\\Users\\\\plk7504\\\\Desktop\\\\xmloutput.xml would be translated to C:\\Users\\plk7504\\Desktop\\xmloutput.xml right? so the problem you were seeing is because you were essentially trying to "escape" other characters such as '\\U'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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