我正在尝试使用 Javascript 解析 XML 文件,但我不断收到相同的错误:
SyntaxError: malformed hexadecimal character escape sequence
$.get('C:\Users\xxxxxx\Desktop\xmloutput.xml', function(xml) {
它指向 C 之前的单引号。我查找了错误,但没有太多关于如何解决它的信息。或者我的语法不正确?这是我的代码:
$(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]);
});
最佳答案
更新路径为:
C:\\Users\\plk7504\\Desktop\\xmloutput.xml
另请参阅:How to open a local disk file with Javascript?
说明: C:\\Users\\plk7504\\Desktop\\xmloutput.xml 将被转换为 C:\Users\plk7504\Desktop\xmloutput.xml 对吗?所以你看到的问题是因为你本质上是试图“转义”其他字符,例如 '\U'
关于javascript - 尝试使用 Javascript/Jquery 解析 XML 文件时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24499214/