title: CSV-import via jquery - variable locked in
body: <p>i use a nice code to import csv data. 
  However, my variable seems to be somehow caught within the function so i cannot access it from other places in my .js ...</p>
  
  <p>see my two alert functions in the code below.</p>
  
  <p>Code copied from post(<a href="https://stackoverflow.com/questions/7431268/how-read-data-from-csv-file-using-javascript">How to read data From *.CSV file using javascript?</a>)</p>
  
  <pre><code>$(document).ready(function () {
      $.ajax({
          type: "GET",
          url: "../recipes.csv",
          dataType: "text",
          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(data[j]);
              }
              lines.push(tarr);
          }
      }
      dataArray = (lines + "").split(';');
  
      alert(dataArray[1]); // here it works
  }
  alert(dataArray[1]); // here it doesn't work: "ReferenceError: dataArray is not defined"
  </code></pre>