我有一些用于自定义 Django 管理员的 jquery 文件。我想使用 Google 的jquery-csv从本地 csv 文件中绘制代码表。
function getCodeTable() {
$.ajax({
url: "admin/js/custom/Sample100.csv",
aync: false,
success: function (csv) {
csv_as_objects = $.csv.toObjects(csv);
},
dataType: "text",
complete: function () {
return csv_as_objects;
}
});
}
原始 csv 文件由 Postgres 创建。当我将它放入我的项目并尝试访问它时,我收到此错误:
CSVDataError: Illegal quote [Row:3]
认为csv有问题,我在Notepad ++中打开它来查找问题,但我没有看到。
我已经通过https://csvlint.io/运行了该文件,结果它是有效的。然后我下载了相同文件的标准化 CSV。当我打开它并查看它时,它所做的唯一更改是在主键周围加上引号。我把它放在我的项目中并运行,并返回相同的错误:
CSVDataError: Illegal quote [Row:3]
我认为 Postgres 以某种方式给了我一些格式错误的 csv 文件,所以我访问了这个站点https://www.appsloveworld.com/sample-csv-file/并下载了一个名为 csv 文件以Sample100.csv
查看它是如何工作的。
返回相同的错误:
CSVDataError: Illegal quote [Row:3]
所以现在看来我输入的任何 csv 文件都会返回相同的错误。我不知道这是否是jquery-csv
库问题(怀疑),或者我的代码中是否缺少某些内容
codeTable.csv 的前 5 行:
"codecategoryid","codecategorydesc","codetypeid","codetypedesc"
15,"Address Types",60,"Mailing Address"
15,"Address Types",59,"Physical Address"
15,"Address Types",61,"PO Box"
8,"Agricultural Employee Types",22,"Distribution Worker"
我从https://csvlint.io/下载的 codeTable.csv 的前 5 行标准化 CSV :
"codecategoryid","codecategorydesc","codetypeid","codetypedesc"
"15","Address Types","60","Mailing Address"
"15","Address Types","59","Physical Address"
"15","Address Types","61","PO Box"
"8","Agricultural Employee Types","22","Distribution Worker"
从https://www.appsloveworld.com/sample-csv-file/下载的 Sample100.csv 的前 5 行:
Serial Number,Company Name,Employee Markme,Description,Leave
9788189999599,TALES OF SHIVA,Mark,mark,0
9780099578079,1Q84 THE COMPLETE TRILOGY,HARUKI MURAKAMI,Mark,0
9780198082897,MY KUMAN,Mark,Mark,0
9780007880331,THE GOD OF SMAAL THINGS,ARUNDHATI ROY,4TH HARPER COLLINS,2