Ajax Response Content-Disposition App

I am creating a website that communicates via javascript using a webservice that accepts sent json requests. I am sending these requests using XMLHttpRequest. In some cases, the service returns a download response:

Example:

Content-Disposition: attachment; filename="somefile.txt" Content-Type: application/force-download Content-Length: 3 123 

If document.location is pointed to a URL that is responsible for a response similar to the one above, the browser will automatically offer the user a file download dialog.

My question is: can I achieve the same effect with XMLHttpResponse objects? is there an Iframe trick or something else? Unfortunately, XMLHttpRequest objects do not have target objects, for example, in html forms, because if I can just redirect the full response (with headers) to a new page or a hidden iframe, the problem will be solved, I think.

+4
source share
1 answer

I think no. But you can try sending the hidden form to a hidden iframe.

0
source

All Articles