{"id":1435,"date":"2015-06-03T13:23:34","date_gmt":"2015-06-03T11:23:34","guid":{"rendered":"http:\/\/www.capri-soft.de\/blog\/?p=1435"},"modified":"2015-06-03T14:16:50","modified_gmt":"2015-06-03T12:16:50","slug":"javascript-csv-datei-zeilenweise-einleise-read-csv-file-line-by-line","status":"publish","type":"post","link":"https:\/\/www.capri-soft.de\/blog\/?p=1435","title":{"rendered":"Javascript: CSV Datei zeilenweise einleise \/ read csv file line by line"},"content":{"rendered":"<h1>Problem<\/h1>\n<p>Eine CSV Datei soll zeilenweise per Javascript eingelesen werden<br \/>\nA CSV file should be read line by line via javascript<\/p>\n<h1>Ansatz &#8211; Approach<\/h1>\n<p>Es wird die $.ajax-Funktion von JQuery verwendet. JQuery wird entsprechend http:\/\/jquery.com\/download\/ eingebunden.<br \/>\nWe are using the $.ajax-Method of JQuery. JQuery will be embedded according to http:\/\/jquery.com\/download\/.<\/p>\n<h1>L\u00f6sung &#8211; Solution<\/h1>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$(document).ready(function() {\r\n    $.ajax({\r\n        type: &quot;GET&quot;,\r\n        url: &quot;data.txt&quot;,\r\n        dataType: &quot;text&quot;,\r\n        success: function(data) {processData(data);}\r\n     });\r\n});\r\n\r\nfunction processData(allText) {\r\n    var allTextLines = allText.split(\/\\r\\n|\\n\/);\r\n    var headers = allTextLines&#x5B;0].split(&#039;,&#039;);\r\n    var lines = &#x5B;];\r\n\r\n    for (var i=1; i&amp;lt;allTextLines.length; i++) {\r\n        var data = allTextLines&#x5B;i].split(&#039;,&#039;);\r\n        if (data.length == headers.length) {\r\n\r\n            var tarr = &#x5B;];\r\n            for (var j=0; j&amp;lt;headers.length; j++) {\r\n                tarr.push(headers&#x5B;j]+&quot;:&quot;+data&#x5B;j]);\r\n            }\r\n            lines.push(tarr);\r\n        }\r\n    }\r\n    \/\/ alert(lines);\r\n}\r\n<\/pre>\n<iframe src=\"http:\/\/www.facebook.com\/plugins\/like.php?href=https%3A%2F%2Fwww.capri-soft.de%2Fblog%2F%3Fp%3D1435&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light\" scrolling=\"no\" frameborder=\"0\" allowTransparency=\"true\" style=\"border:none; overflow:hidden; width:450px;margin-top:5px;\"><\/iframe>","protected":false},"excerpt":{"rendered":"<p>Problem Eine CSV Datei soll zeilenweise per Javascript eingelesen werden A CSV file should be read line by line via javascript Ansatz &#8211; Approach Es wird die $.ajax-Funktion von JQuery verwendet. JQuery wird entsprechend http:\/\/jquery.com\/download\/ eingebunden. We are using the $.ajax-Method of JQuery. JQuery will be embedded according to http:\/\/jquery.com\/download\/. L\u00f6sung &#8211; Solution $(document).ready(function() { &hellip; <a href=\"https:\/\/www.capri-soft.de\/blog\/?p=1435\" class=\"more-link\"><span class=\"screen-reader-text\">Javascript: CSV Datei zeilenweise einleise \/ read csv file line by line<\/span> weiterlesen <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[30],"tags":[],"class_list":["post-1435","post","type-post","status-publish","format-standard","hentry","category-javascript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p4yGeN-n9","jetpack_likes_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1435","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1435"}],"version-history":[{"count":3,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1435\/revisions"}],"predecessor-version":[{"id":1439,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1435\/revisions\/1439"}],"wp:attachment":[{"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1435"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1435"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.capri-soft.de\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1435"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}