title: how to assign value of readAsDataURL() to a variable?
body: <p>okay so I've seen many examples and questions on using readAsDataURL(), but none of them seem to resolve my issue. Following is my code :</p>
  
  <pre><code>$(document).ready(function(){
      var fileReader = new FileReader();
      $("form").submit(function(e){
          e.preventDefault();
          console.log(fileReader.readAsDataURL(document.getElementById("userfile").files[0]));
      });
  });
  </code></pre>
  
  <p>what i get in console is <code>undefined</code> . I'm trying to get the base64 encoded file data on a variable so that i can upload it using ajax. Can anyone tell me what i am doing wrong?</p>