[英]Need to replace my data from json to csv file
I'm working with json file but I need to replace it with csv file.我正在使用 json 文件,但我需要用 csv 文件替换它。 Do I need to use a library to do that or can I change the jQuery get from json to csv?
我需要使用库来做到这一点,还是可以将 jQuery get 从 json 更改为 csv? I've tried that but no luck not working.
我试过了,但没有运气不起作用。
My javascript code is th我的 javascript 代码是
$(document).ready(function() { $.ajax({ url: 'somefile.json', type: "GET", dataType: "json", success: function (data) { $(".score-text").each(function( index, value ) { value.innerText = data['box'+(index+1)].total; }); $(".data").each(function( index, value ) { var boxIndex = Math.floor(index/4); width = data['box'+(boxIndex+1)]['bar'+(index+1-boxIndex*4)]; value.innerText = width; value.style.width = width; }); } }); });
I'm using csv to array but getting some errors this is my code我正在使用 csv 进行数组,但出现一些错误,这是我的代码
$(document).ready(function() { $.ajax({ url: "somefile.csv", success: function (csvd) { data = $.csv2Array(csvd); }, dataType: "text", complete: function (data) { $(".score-text").each(function( index, value ) { console.log(data); value.innerText = data['box'+(index+1)].total; }); $(".data").each(function( index, value ) { var boxIndex = Math.floor(index/4); width = data['box'+(boxIndex+1)]['bar'+(index+1-boxIndex*4)]; value.innerText = width; value.style.width = width; }); } }); });
Thanks谢谢
jQuery does not know about CSV files. jQuery 不知道 CSV 文件。 You would need to request it as
dataType: "text"
, then parse it yourself.您需要将其请求为
dataType: "text"
,然后自己解析它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.