I'm getting the following UndetectableDelimiter error in the console when trying to parse CSV files with Papa Parse:
The data array does not contain anything. Test2.csv is a comma delimited file created and saved in Excel. It has 4 columns and 4 rows. The file is located in the same folder as the HTML file. See the CSV file here: https://filebin.net/f9kgeercbsw775lv
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.min.js"></script>
<script>
$(function() {
var results = Papa.parse('test2.csv', {
delimiter: "",
newline: "",
complete: function(results) {
console.log(results);
data = results.data;
}
});
You're specifying an empty string as the delimiter. Set your delimiter to comma and you'll at least avoid that error.
delimiter: ',',
Edit: The only way I've used Papa.parse()
is with a file upload. Here's how:
<label for="theCSV">CSV file:</label>
<input type="file" id="theCSV" name="theCSV" />
<div id="results"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.min.js"></script>
<script>
$(function() {
var csv;
$("#theCSV").change(function(e) {
Papa.parse(e.target.files[0], {
download: true,
header: true,
delimiter: ',',
skipEmptyLines: true,
error: function(err, file, inputElem, reason) {
$('#results').append('Error: ' + err + ' : ' + reason + '<br>');
return false;
},
complete: function(results) {
$('#results').append(JSON.stringify(results.data) + '<br>');
}
});
});
});
</script>