JS reads CSV file and displays it using JSON _javascript tips

Source: Internet
Author: User

Summary:

Previously shared with JS to download JSON data as CSV file, facilitate later management. But for testers who want to be able to show the task as a page, they do an example of displaying a CSV file on a page.

Code:

Copy Code code as follows:

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>csv</title>
<script src= "Http://code.jquery.com/jquery-1.11.0.min.js "></script>
<script src= "./papaparse.min.js" ></script>
<style>
html,body{
font-size:14px;
font-family: ' Microsoft yahei ', Tahoma,verdana,simsun,sans-serif;
}
Table {width:85%;margin:30px Auto;}
</style>
<body>
<table id= "Table" border= "1" >
<caption>csv Turn json</caption>
<thead>
<tr>
<th>Vehicle</th>
<th>Date</th>
<th>Location</th>
<th>Speed</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
<script>
Papa.parse ('./result.csv ', {
Download:true,
Complete:function (Results) {
var data = results.data, html;
for (var i = 1, _l = Data.length-1 i < _l; i++) {
var item = Data[i];
html + + ' <tr><td> ' +item[0].substring (1) + ' </td><td> ' +item[1].substring (1) + ' </td> <td> ' +item[2].substring (1) + ' </td><td> ' +item[3].substring (1) + ' </td></tr> ';
}
$ (' #table tbody '). Append (HTML);
}
});
</script>
</body>

Effect Chart:

Note: The above example requires a service environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.