|
建议读取的时候将csv文件编码转换为UTF-8
-
- <script src="ttasp/lib/js/jquery.min.js" ></script>
- <script src="ttasp/lib/js/jquery.csv.js" ></script>
- var csv_file_API = '/202269102423.csv';
- $.ajax({
- type: 'GET',
- url: csv_file_API,
- dataType: 'text',
- success: function (data) {
-
- var data=$.csv.toObjects(data);
-
- var theHtml=createTable(data);
-
- $('#theResult').html(theHtml);
-
- }, // end: Ajax success API call
- error: function (e) {
- alert('An error occurred while processing API calls');
- console.log("API call Failed: ", e);
- },
- });
-
- function createTable(data){
- var html='<table border=1>';
- if(data[0].constructor===Object){
- html+='<tr>\r\n';
- for(var item in data[0]){
- html+='<th>'+item+'</th>\r\n';
- }
- html+='</tr>\r\n';
- for(var row in data){
- html+='<tr>\r\n';
- for(var item in data[row]){
- html+='<td>'+data[row][item]+'</td>\r\n';
- }
- html+='</tr>\r\n';
- }
- }
-
- return html;
- }
复制代码 |
|