title: How to save binary file on client in jquery .post
body: <p>I have handler with this code:</p>
  
  <pre><code>    HttpRequest request = context.Request;
      HttpResponse response = context.Response;
  
      if (request["Type"] != null)
      {
          try
          {
              string resultFile = null;
              string fileName = string.Empty;
  
              int type = Convert.ToInt32(request["Type"]);
  
              switch (type)
              {
                  case 1:
                      fileName = "InnerQuery.doc";
                      resultFile = GenerateInnerQuery(Id);
                      break;
  
                  case 2:
                      fileName = "CourierQuery.doc";
                      resultFile = GenerateCourierQuery(Id);
                      break;
  
                  case 3:
                      fileName = "TransportDogovor.doc";
                      resultFile = GenerateTransportDogovor(Id);
                      break;
  
                  case 4:
                      fileName = "TransportQuery.doc";
                      resultFile = GenerateTransportQuery(Id);
                      break;
  
                  case 5:
                      fileName = "PassQuery.doc";
                      resultFile = GeneratePassQuery(Id);
                      break;
              }
  
              if (resultFile != null)
              {
                  response.Clear();
                  response.AddHeader("pragma", "no-cache");
                  response.AddHeader("cache-control", "private");
                  response.CacheControl = "no-cache";
                  response.ContentType = "application/octet-stream";
                  response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}",
                      System.Web.HttpUtility.UrlPathEncode(fileName)));
                  response.OutputStream.Write(File.ReadAllBytes(resultFile), 0, (int)(new FileInfo(resultFile)).Length);
                  response.End();
              }
          }
          catch (Exception ex)
          { }
      }
  </code></pre>
  
  <p>On client i post data to handler with jQuery.post():</p>
  
  <pre><code>var handler = "GetWord.ashx?Type=6";
      var initiationDateFrom = $("#&lt;%=InitiationDateFromTxt.ClientID%&gt;").val();
      var initiationDateTill = $("#&lt;%=InitiationDateTillTxt.ClientID%&gt;").val();
      var queryDateFrom = $("#&lt;%=QueryDateFromTxt.ClientID%&gt;").val();
      var queryDateTill = $("#&lt;%=QueryDateTillTxt.ClientID%&gt;").val();
      var queryNumber = $("#&lt;%=NumberTxt.ClientID%&gt;").val();
      var initiator = $("#&lt;%=InitiatorTxt.ClientID%&gt;").val();
      var state = $("#&lt;%=StateList.ClientID%&gt;").val();
      $.post(handler,
      {
          InitiationDateFrom: initiationDateFrom,
          InitiationDateTill: initiationDateTill,
          QueryDateFrom: queryDateFrom,
          QueryDateTill: queryDateTill,
          QueryNumber: queryNumber,
          Initiator: initiator,
          State: state
      }, function (data) {
         /*here i should save my file*/
      });
  </code></pre>
  
  <p>I recieve binary word-file in "data", but can't to save it on client.</p>
  
  <p>last time i use:</p>
  
  <pre><code>window.location = handler;
  </code></pre>
  
  <p>but with jQuery.post it not work.</p>