[英]Undefined Function for Imported Library in JavaScript
I'm parsing a CSV file into arrays and using jquery.csv to do the grunt work. 我将CSV文件解析为数组,并使用jquery.csv进行了艰苦的工作。 My script reads:
我的脚本显示为:
<script>
$(document).ready(function() {
// The event listener for the file upload
document.getElementById('txtFileUpload').addEventListener('change', upload, false);
// Method that checks that the browser supports the HTML5 File API
function browserSupportFileUpload() {
var isCompatible = false;
if (window.File && window.FileReader && window.FileList && window.Blob) {
isCompatible = true;
}
return isCompatible;
}
// Method that reads and processes the selected file
function upload(evt) {
if (!browserSupportFileUpload()) {
alert('The File APIs are not fully supported in this browser!');
} else {
var data = null;
var file = evt.target.files[0];
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(event) {
var csvData = event.target.result;
data = $.csv.toArrays(csvData);
if (data && data.length > 0) {
alert('Imported -' + data.length + '- rows successfully!');
} else {
alert('No data to import!');
}
};
reader.onerror = function() {
alert('Unable to read ' + file.fileName);
};
}
}
});
My console reads that there is an "Uncaught TypeError: Cannot read property 'toArrays' of undefined". 我的控制台读取到一个“未捕获的TypeError:无法读取未定义的属性'toArrays'”。 Also in the head section, I imported the library using
<script src="jquery.csv-0.71.js"></script>
, the JS file residing in the same folder. 同样在头部,我使用
<script src="jquery.csv-0.71.js"></script>
(位于同一文件夹中的JS文件)导入了库。 Any ideas why this error is occurring? 任何想法为什么会发生此错误? Have I imported the library incorrectly, do I need to initialize something?
我是否错误地导入了库,是否需要初始化某些内容? Thanks!
谢谢!
Make sure you're importing jquery.csv-0.71.js
after importing jQuery and that your script is running after both. 确保在导入jQuery 之后要导入
jquery.csv-0.71.js
,并且脚本在这两者之后都在运行。
<script src="jquery.js"></script>
<script src="jquery-csv.js"></script>
<script>/* Your script */</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.