0

This is my CSV file:

Item, Quantity, Price;
LED, 100, $10;
PIR, 1, $5;
DS18B20, 10, $5;  

This is my jquery file:

$(document).ready(function() {
    $.ajax({
        url: "data.csv",
        success: function(result) {
            var data = result;
            var arr = data.split(";");
            var len = arr.length - 1;
            var a = 0;
            var b = 0;
            while (a < len) {
                var orr = arr[a].split(",");
                var err = orr.length;
                b = 0;
                while (b < err) {
                    if (a == 0) {
                        alert(orr[b]);
                        b = b + 1;
                    } else if (a > 0) {
                        alert(orr[b]);
                        b = b + 1;
                    }
                };
                a = a + 1;
            };
        }
    });
});

this code gets the data and alerts. How do I get all the data turn the into a ordered table (i.e. the first line should be a table header).

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
TechDinoKing
  • 51
  • 1
  • 8
  • 1
    Here you go: http://www.w3schools.com/jsref/met_document_createelement.asp. And if you want to step things up, you might want to look at: React (https://github.com/reactjs) or knockout (http://knockoutjs.com/) – Patrick Aleman Sep 07 '16 at 09:53
  • Thanks...And also what should i learn to use react.js ? – TechDinoKing Sep 07 '16 at 11:56
  • The React framework is a lightweight javascript library that enables binding data from javascript to HTML elements. The only thing you need to learn to use react is Javascript and HTML. – Patrick Aleman Sep 07 '16 at 14:33
  • But i want to do it with only Jquery... How do i do it ? – TechDinoKing Sep 07 '16 at 17:35
  • http://stackoverflow.com/questions/1413952/how-to-create-a-new-table-with-rows-using-jquery-and-wrap-it-inside-div Not quite an exact duplicate, but it covers creating a table and adding rows to it. – Mic Sep 07 '16 at 20:36
  • But how do i use this code in my project? It's not very straightforward. – TechDinoKing Sep 08 '16 at 07:07

0 Answers0