title: How to allow download of file, that is returned as binary data from AJAX
body: <p>My problem is that I send to client first PDF to download, then I need to check, if some data exists in my database, then depending on that check I need to show question that if user want to download another PDF, that I generates. </p>
  
  <p>My Code:</p>
  
  <pre><code> //Here I just make dialog for question
   $('#printDWInfo').dialog({
              resizable: false,
              modal: true,
              autoOpen: false
          });
  
   //Here is my problem :)
   $('#generujWydruk').click(function (event) {
              event.preventDefault();
              $('#printForm').submit(); // &lt;-- sending first request and client get first PFD file
              $.post('&lt;%: ResolveUrl("~/Reports/KPiRReportDWCheck") %&gt;', &lt;-- check for another data
                  $("#printForm").serialize(),
                  function(data) {
                      if (data.length &gt; 0) {
                          $("#printDWInfo").dialog( "option", "buttons", [
                              {
                                  text: "Tak",
                                  click: function () {
                                      $.ajax({ type: "POST",
                                          url: '&lt;%= Url.Action("PrintDWList","Reports")%&gt;',
                                          datatype: "json",
                                          traditional: true,
                                          data:{'ids': data },
                                          success: function (data2) {
                                              //I don't know what to do here
                                          }
                                      });
                                      $(this).dialog("close");
                                      }
                                  }, {
                                  text: "Nie",
                                  click: function () {
                                      $(this).dialog("close");
                                      }
                              }
                          ]);
                          $('#printDWInfo').dialog("open");
                      }
                  }
              );
  </code></pre>
  
  <p>If client click on button "Tak" in dialog, I use ajax request, because I can pass to controler array of int, that is returned by <code>$.post('&lt;%: ResolveUrl("~/Reports/KPiRReportDWCheck") %&gt;'</code>.
  In success function of my ajax request FireBug show me that <code>data2</code> is binary data of my PDF file, what I need to do to allow client to download this PDF file? </p>