YazanLpizra
YazanLpizra

Reputation: 540

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]);
});

Upvotes: 1

Views: 419

Answers (1)

Davie Brown
Davie Brown

Reputation: 717

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'

Upvotes: 1

Related Questions