title: download Excel File from request.responseText
body: <p>In my application (Yii) I have a Ajax Submit Button which triggers the generation of an Excel file (using PHPExcel).
  On success I use a hidden form to submit the file to get it downloaded :</p>
  
  <pre><code>&lt;div class="reporting"&gt;
      &lt;?php
          $this-&gt;beginWidget('zii.widgets.jui.CJuiDialog',array(
              'id'=&gt;'mydialog',
              'options'=&gt;array(
                  'title'=&gt;'Warning!',
                  'autoOpen'=&gt;false, //true,
                  'modal'=&gt;'true',
                  'width'=&gt;'auto',
                  'height'=&gt;'auto',
                  'open' =&gt; 'js:function(event, ui) {
                  }',
                  'close' =&gt; 'js:function(event, ui) {
                      $(".ui-dialog:has(#mydialog)").empty().remove();
                  }',
              )
          )); 
      ?&gt;
      &lt;table class="contentheader"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;?php echo CHtml::DropDownList('dropDownId', $lastyear, $yearslist, array('options'=&gt;array($lastyear=&gt;array('selected'=&gt;true)) )); ?&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;br /&gt;
      &lt;?php echo CHtml::ajaxSubmitButton('Form Ajax Submit Button',
          CHtml::normalizeUrl(array('/planning/xlsAbsences')), 
              array(
                  'type'=&gt;'POST',
                  'beforeSend' =&gt; "function(request) { console.log('beforeSend'); }",
                  'data'=&gt;'js:$("#select-year-form").serialize()+"&amp;year="+$("#dropDownId :selected").text()',
                  'success' =&gt; function(response, status, request){
                      $("#mydialog").dialog("close"); 
                      var disp = request.getResponseHeader("Content-Disposition");
                      if (disp &amp;&amp; disp.search("attachment") != -1) {
                          var filename = disp.substring(disp.indexOf("filename=") + 10, disp.length-1);
                          var form = $("&lt;form method=\"POST\" action=\"index.php?r=planning/dl\"&gt;");
                          form.append($("&lt;input type=\"hidden\" name=\"content\" value=\"" + request.responseText + "\"&gt;"));
                          form.append($("&lt;input type=\"hidden\" name=\"filename\" value=\"" + filename + "\"&gt;"));
                          $("body").append(form);
                          form.submit();
                      }
                  }
                  'complete' =&gt; "function(request) { console.log(request); }",
                  'error' =&gt; "function(data) { alert('erro'+data); }",
              ),
              array('name' =&gt; 'run', 'class' =&gt; 'btn btn-success')
      ); ?&gt;
      &lt;?php $this-&gt;endWidget('zii.widgets.jui.CJuiDialog');
          echo CHtml::link(Yii::t('app','app.menu.reporting.planning.xlsabsence'), '#', array( 
              'onclick'=&gt;'$("#mydialog").dialog("open"); return false;',
          ));
      ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Problem is that the generated file is not a valid Excel file.
  I suppose that the content of the Excelfile is in request.responseText.
  I have seen that the generated file that can't be opened by Excel, is encoded in UTF (without BOM).
  If I generate the file without Ajax Submit Button the file is ok. But its seems to be encoded in ANSI.
  I was using Notpad++ to see encoding information. When I convert UTF (without BOM) to ANSI the result is not better.</p>
  
  <p>What am I missing here ?</p>
  
  <p>EDIT :
  I don't know if my description is not clear enough - the Excel file does not exist. The Excel file content is generated when submitting Ajax Submit Button in a CJuiDialog - for example the user opens dialog and chosses a parameter - this generates an Excel File depending on the parameter selected by the user.
  As the file does not exist I can't see how to download it. The only solution I found to go through a hidden form.</p>
  
  <p>EDIT2 : 
  I published the whole view code (above)</p>