title: posting data to server with jquery and downloading response as file
body: <p>I'm creating a file server, where users can optionally encrypt their files, and ideally enter a password in the browser to decrypt them on the fly and download them (in a chunked fashion of course, easier for PHP).  The decrypted data should never be saved to disk.</p>
  
  <p>So right now the user enters the password, jQuery sends a post to the download page with the password and a variable "checking" set to true.  The download page then returns a json object with a true or false indicating if it could decrypt the file or not, this part works fine.  </p>
  
  <p>Depending on the response, it will either ask the user for another password if the response variable is false, or it will send out a new request with just the password and checking set to false, if the original response was true (correct password).</p>
  
  <p>PHP then responds with the first chunk of the file to be downloaded.  Issue is, Firefox never brings up a download prompt.  Evidently you can't try to download files using jquery $.post()</p>
  
  <p>So, I guess I need another way to do this client part.  Any help would be appreciated :)</p>
  
  <p>Here's the applicable client-side code.</p>
  
  <pre><code>        Download: function(item) {
  
          if (item) { var file = Content.files[(item ? $(item).attr('id').split('_')[1] : Content.selected.files[0])]; }
  
          else { if (Content.selected.files.length != 1 || Content.selected.folders.length != 0) { return; } var item = Content['files'][Content.selected.files[0]]; }
  
          if (file['encrypted']) {
  
              $.prompt({
  
                  input: {
  
                      html: "Please enter the password to download this encrypted file: &lt;br /&gt;&lt;br /&gt;&lt;input type='password' name='password' style='width:400px;' /&gt;",
                      buttons: { "Submit" : true },
                      persistent: false,
  
                      submit: function(event, value, message, form) {
  
                          $.prompt.goToState('pause');
  
                          $.post("?p=download&amp;id="+file['id'], {
  
                              password: form.password, checking: true
  
                          }, function (response) {
  
                              if (response.ok) {  
  
                                  $.post("?p=download&amp;id="+file['id'],{ password: form.password, checking: false }); $.prompt.close();
  
                              } else {
  
                                  $.prompt.getStateContent('output').find('.jqimessage').html(response.result);
  
                                  $.prompt.goToState('output');
                              }
  
                          },"JSON");  
  
                          return false;
                      }
  
                  },
  
                  pause: {
  
                      html: 'Please Wait... &lt;img src="images/load_icon.gif" alt="" style="margin-bottom:-2px;margin-left:4px;height:12px;" /&gt;',
                      buttons: { },
                      persistent: true,
  
                  },
  
                  output: {
  
                      buttons: { Close: "Close" },
                      persistent: false
                  }                   
              });
  
          } else {
  
              window.location.href = "?p=download&amp;id="+file['id'];    
          }           
      },
  </code></pre>