title: JavaScript: How to open a returned file via AJAX
body: <p>This is similar to: <a href="https://stackoverflow.com/questions/761682/how-to-open-a-file-using-javascript">How to open a file using JavaScript?</a></p>
  <h3>Goal: to retrieve/open a file on an image's double click</h3>
  <pre><code>function getFile(filename){
     // setting mime this way is for example only
     var mime = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
     
     jQuery.ajax({ url      : 'get_file.pl',
                   data     : {filename:filename}, 
                   success  : function(data){
                                 var win = window.open('','title');
                                 win.document.open(mime);
                                 win.document.write(data);
                                 win.document.close();
                              }
                 });
  }
  
  jQuery('#imgID').dblclick(function(){ 
     getFile('someFile.docx');
  });
  </code></pre>
  <p>I'm doing this off the top of my head, but I think the above would work for text files, but not binary.  Is there a plugin that does this properly?  The ideal would be to open the file in the browser (or application), rather than download, but I doubt that is a dream.  If the file must be downloaded with the save/open dialog, that's fine.</p>
  <hr />
  <h3>Edit:</h3>
  <p>One piece of information that I forgot to mention is that I'd like this to be a POST request.  This is partly why I was looking at AJAX to begin with.  I've seen workarounds that have created forms/iframes to do something similar, but I was looking for a better handler of the returned info.</p>