..._jquery 修改csv文件">
赞
踩
数据请求简单粗暴的利用了HTTP,完整的数据请求移步:https://blog.csdn.net/qq_31052401/article/details/98882704
目录
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport"
- content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <style>
-
- </style>
- </head>
- <body>
- <script>
- //请求csv文件
- function getCSV(url,f){
- let xmlHttp = new XMLHttpRequest();
- xmlHttp.open("GET", url, true);// 异步处理返回
- xmlHttp.onreadystatechange = function callback() {
- if (xmlHttp.readyState === 4) {//4代表执行完成
- if(xmlHttp.status === 200){
- //console.log(xmlHttp.responseText);
- f.call(this,xmlHttp.responseText);
- }
- }
- };
- xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
- xmlHttp.send(null);
- }
-
-
- //csv字符串 to Array
- function CSV(csvString) {
- let data = [];
- let relArr = csvString.split("\r\n");// '\r'
- if(relArr.length > 1) {
- let title = relArr[0].split(',');
- let title_arr = title.keys();
- for(let key = 1, len = relArr.length-1; key < len; key++) {
- let values = relArr[key];
- let objArr = values.split(",");
- let obj = {};
- for(let i=0;i<title.length;i++){
- obj[title[title_arr.next().value]] = objArr[i];
- }
- data.push(obj);
- title_arr = title.keys();
- }
- }
- return data;
- }
-
- //..........
-
- getCSV('data.csv',function (data) {
- console.log(CSV(data));
- });
-
- </script>
- </body>
- </html>
- ---------------------
- 版权声明:本文为CSDN博主「伍拾贰赫兹」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。
- 原文链接:https://blog.csdn.net/qq_31052401/article/details/98884827
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。