title: Read the content of file with FileReader and send it via ajax
body: <p>I would like to send to my server side the content of a file via ajax.
  I am reading a file on the client side using FileReader and send it to my server side like this:</p>
  
  <pre><code>function readFile(file) {
    var content = "";
    var reader = new FileReader();
  
    reader.onload = function(e) {
       content = reader.result;
       console.log(content);
    }
  
    console.log(content);
  
    reader.readAsText(file);
    return content;
  }
  
  var data = {};
  data.content = readFile(file);
  data.surname = surname;
  data.first = firstname;
  
  console.log(data);
  sendData(data, global_url + '/instance');
  
  function sendData(data, url) {
      console.log("Try to send the data");
      $.ajax({
          type: 'POST',
          data: JSON.stringify(data),
          contentType: 'application/json',
          url: url,
          success: function (data) {
              console.log('success');
              console.log(JSON.stringify(data));
              if (data === 'done')
              {
                  window.location.href = "/";
              } else {
                  alert('Error');
              }
          },
          error: function () {
              console.log('process error');
          }
      });
  }
  </code></pre>
  
  <p>However, I don't know how to return the variable.
  The second console.log in the function readFile is equals to "". </p>