未定义XMLHttpRequest-爸爸解析 [英] XMLHttpRequest is not defined - Papa parse
问题描述
[已解决]对于阅读此书的任何人,Papa Parse都是浏览器的解析器,而不是Node.js. Baby Parse用于Node.js,但要知道它的功能并不广泛,并且不能直接从文件(仅从字符串)进行解析.
[SOLVED] For anyone who reads this, Papa Parse is a parser for the browser, not Node.js. Baby Parse is used for Node.js, but know that it isn't as extensive in its functionality and can't parse straight from a file, only from a string.
在papaparse.js
文件中,具有以下代码行:
In the papaparse.js
file, it has this line of code:
xhr = new XMLHttpRequest();
这似乎是导致错误的原因,我不确定如何解决.
This seems to be causing the error and I'm not sure how to get around it.
我的代码:
var Papa = require('papaparse');
var data;
process.argv.forEach(function(val, index, array) {
console.log(index + ': ' + val);
});
var file = process.argv[2];
console.log("File: " + file);
// Parse the file
Papa.parse(file, {
header: true,
download: true,
dynamicTyping: true,
complete: function(results) {
data = results;
console.log(data);
}
});
任何想法将不胜感激:)
Any ideas would be appreciated :)
推荐答案
实际上,现在可以在节点环境中使用PapaParse: https://github.com/mholt/PapaParse/blob/master/README.md#papa-parse-for-node
actually PapaParse can be used in a node environment now: https://github.com/mholt/PapaParse/blob/master/README.md#papa-parse-for-node
但是,您必须在parse-config中禁用下载"选项,否则库将尝试通过XMLHttpRequest加载文件.
however, you have to disable the "download" option in the parse-config, since otherwise the library will attempt to load the file via XMLHttpRequest.
这篇关于未定义XMLHttpRequest-爸爸解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!