Skip to content

Instantly share code, notes, and snippets.

@EugeneZheleznov
Created April 19, 2022 12:52
Show Gist options
  • Save EugeneZheleznov/389f1a8af69ff0c7ea483219ba890de1 to your computer and use it in GitHub Desktop.
Save EugeneZheleznov/389f1a8af69ff0c7ea483219ba890de1 to your computer and use it in GitHub Desktop.
[CSV в HTML таблицу] #csv #jquery
jQuery.noConflict();
(function ($) {
$.ajax({
url: 'http://getdevs.ru/LoginAndPasswordWebCabinet.csv',
dataType: 'text',
}).done(successFunction);
function successFunction(data) {
var allRows = data.split(/\r?\n|\r/);
var table = '<table>';
for (var singleRow = 0; singleRow < allRows.length; singleRow++) {
if (singleRow === 0) {
table += '<thead>';
table += '<tr>';
} else {
table += '<tr>';
}
var rowCells = allRows[singleRow].split(',');
for (var rowCell = 0; rowCell < rowCells.length; rowCell++) {
if (singleRow === 0) {
table += '<th>';
table += rowCells[rowCell];
table += '</th>';
} else {
table += '<td>';
table += rowCells[rowCell];
table += '</td>';
}
}
if (singleRow === 0) {
table += '</tr>';
table += '</thead>';
table += '<tbody>';
} else {
table += '</tr>';
}
}
table += '</tbody>';
table += '</table>';
$('body').append(table);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment