title: Using jQuery and iFrame to Download a File
body: <p>I have the following code to download a <code>.csv</code> file:</p>
  
  <pre><code>$.ajax({
      url: urlString,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      cache: false,
      success: function(data) {
          if (data) {
              var iframe = $("&lt;iframe/&gt;").attr({
                  src: data,
                  style: "visibility:hidden;display:none"
              }).appendTo(buttonToDownloadFile);
          } else {
              alert('Something went wrong');
          }
      }
  });
  </code></pre>
  
  <p>The <code>urlString</code> is pointing to a Restful service that generates the <code>.csv</code> file and returns the file path which is assigned to the src attribute for the iFrame. This works for any <code>.csv</code> files but I'm having problems with <code>.xml</code> files. </p>
  
  <p>When I use the same code but changing the <code>contentType</code> to <code>text/xml</code> and use it for downloading <code>.xml</code> files this doesn't work. </p>
  
  <p>Can I use the same approach here for <code>.xml</code> files?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks to Ben for pointing me to the right direction. It turns out I don't need the ajax call at all. Instead, I can just use the iFrame and its url attribute to call the web service, which will generate the content, add the header (<code>Content-Disposition</code>), and return the stream.</p>