Skip to content

Instantly share code, notes, and snippets.

@rlafuente
Last active May 11, 2018 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlafuente/c78a229c0802ddfa80f3c2ad097b9196 to your computer and use it in GitHub Desktop.
Save rlafuente/c78a229c0802ddfa80f3c2ad097b9196 to your computer and use it in GitHub Desktop.
CSV in jQuery

HTML

<!-- https://github.com/evanplaice/jquery-csv/raw/master/src/jquery.csv.js -->
<script src="jquery-csv.js"></script>
<!-- -->

JavaScript

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "/assets/data.csv",
        dataType: "csv",
        success: function (data) { processCsvData(data); }
    });
});

function processCsvData(data) {
    var rows = $.csv.toObjects(data);
    var filenames = [];
    $.each(rows, function (i, val) {
      var filename = val.slug;
      filenames.insert(filename + ".jpg");
    });
    console.log(filenames);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment