No file upload after AJAX Post in Ember

I have an AJAX Post request located in one of my ember controllers on a Node.js server:

$.ajax({
          type: "POST",
          url: "https://localhost/api/report",
          contentType: "application/json",
          data: payload,
          headers: {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
                    "Cache-Control": "no-cache",
                    "Pragma": "no-cache"
                    }
        });

      

The send request completed successfully and is returned with response headers:

Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Disposition:attachment; filename="report.pdf"
Content-Type:application/pdf
Date:Wed, 15 Jul 2015 19:11:23 GMT
File-Extension:pdf
Number-Of-Pages:1
Transfer-Encoding:chunked
Vary:Origin
X-Powered-By:Express
X-XSS-Protection:0

      

This response should initiate a file download in the browser, but nothing happens. I tested the same request in the same location from outside my Ember app and started uploading successfully.

What is the problem with my request / response? Am I going to get it wrong for Ember?

+3


source to share


1 answer


This is not an Ember issue, this is a javascript issue. You cannot make an ajax request that triggers a file upload this way. However, you can create an iframe, a form, a post in an iframe and in turn initiate a file upload.

See:



+4


source







All Articles