i loading csv file server on client through ajax call , parsing list of lines. however, code cannot find newline character , treats entire file 1 line.
here code
$.ajax({ url: "./data.csv", success: function(data) { var lines = data.split("\n"); // tried did not work // var lines = data.split(/\r\n|\n/); console.log(lines.length); // output 1 } });
here csv (note: delimiter ; instead of , shouldn't cause issue)
category;title;description;price;additional breakfast;traditional breakfast;flour tortilla, scrambled eggs, jack cheese, mild sauce;3.95 breakfast;traditional breakfast;flour tortilla, scrambled eggs, sausage jack cheese, mild sauce;5.95
any ideas?
have check format of csv file? maybe use lf instead of cf newline. try this:
$.ajax({url: "./data.csv", success: function(data) { var lines = data.replace("\r\n", "\n").replace("\r", "\n").split("\n"); // rest of code });
Comments
Post a Comment