title: Reading server-side CSV file
body: <p>I am trying to import CSV data from a CSV file using Javascript. I wrote the code and I don't know what the problem is. When I upload the HTML page to my website it does not work and the script kinda crashes. I tried multiple ways but none worked. Here is the code:</p>
  
  <pre class="lang-js prettyprint-override"><code>$(document).ready(function() {
    $.ajax({
      type: "POST",
      url: "files/testfile.csv",
      dataType: "text",
      data: {
        html: csv
      },
      success: function(data) {
        processData(data);
      }
    });
  });
  
  function processData(allText) {
    var allTextLines = allText.split(/\r\n|\n/);
    var headers = allTextLines[0].split(',');
    var lines = [];
  
    for (var i = 0; i &lt; allTextLines.length; i++) {
      var data = allTextLines[i].split(',');
      if (data.length == headers.length) {
  
        var tarr = [];
        for (var j = 0; j &lt; headers.length; j++) {
          tarr.push(headers[j] + ":" + data[j]);
        }
        lines.push(tarr);
      }
    }
    alert(lines);
  }
  </code></pre>
  
  <p>Help is much appreciated</p>