title: How to download file returned from WCF REST service using AJAX
body: <p>I am using the below code to download the file returned from WCF REST service (file is returned as stream). This code is working fine for text file but the files such as excel and pdf are getting corrupted and they are not getting opened after download.</p>
  
  <p>Can anyone suggest work around for this issue.. </p>
  
  <pre><code>$.ajax({
              url: 'http://localhost:53471/testServices.svc/GetFile?ID=10',
              type: 'GET',               
              cache: false,
              contentType: "application/octet-stream",
              success: function (data,json,status) {                    
                  var blob = new Blob([data]);
                  var link = document.createElement('a');
                  link.href = window.URL.createObjectURL(blob);
                  link.download = "Test document.pdf";
                  link.click();
  
              },
              error: function (data) {
                  alert('Some error Occurred!');
              }
          });
  </code></pre>