0

I have the following issue:

I have a large CSV file with a lot of data that i need to use on an (external (ofcourse approved!)) webpage, utilizing only jQuery.

I found jQuery-csv to be able to manipulate the csv-data into an array. Once i have the data in an array, i'm confident i will be able to do everything i need to do. However, i don't quite get where and how i should 'include' my csv file. It is hosted, available through an url. jQuery-csv never seems to link to a file however, and their demo pages only show content being used through an in-page <input> tag.

To give some extra depth to the situation: A customer wants to use his .csv file-database with a lot of sentences ('i enjoyed this!') and display these sentences at random on his site.

tl;dr: How do i load a .csv file onto my page, so i can use it with jQuery-csv?

Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
Davy
  • 691
  • 1
  • 7
  • 18

1 Answers1

6

How do i load a .csv file onto my page

You can use .ajax(), Something like

$.ajax({
    url: "Path/YourFileName.csv",
    async: false,
    success: function (csvd) {
        data = $.csv.toArrays(csvd);
    },
    dataType: "text",
    complete: function () {
        // call a function on complete 
    }
});

Do load jQuery-csv plugin. before using $.csv.toArrays

Evan Plaice
  • 13,944
  • 6
  • 76
  • 94
Satpal
  • 132,252
  • 13
  • 159
  • 168