title: Returning value from asynchronous JavaScript method?
body: <p>I have run into a problem where I can't seem to get a value from an asynchronous JavaScript method I am running in Jquery. My Jquery looks like this:</p>
  
  <pre><code>$(document).ready( function() {
  $('#splash_image_upload').change( function() {
      var file = this.files[0];
      var blob_string = create_blob(file);
      alert(blob_string);
   });
  </code></pre>
  
  <p>I am able to access the value that comes from the 'onload' event but I cannot seem to return the actual value. I have tried this:`</p>
  
  <pre><code>function create_blob(file) {
      var reader = new FileReader();
      reader.onload = (function() { return function(e) { return e.target.result; }; })();
      reader.readAsDataURL(file);
  }
  </code></pre>
  
  <p>Every time I execute this function the value of the 'blob_str' variable is 'undefined' presumably because the assignment is done before the function is finished. I am not really sure how to go about this. Is there a way I can return this value from this function?? </p>