I posted a question about a less specific topic earlier, located here: Redirect response to download file
You can read the details there if you'd like.
Tim gave me a good answer to just set the document.location.href = '/genericHandlers/DownloadFile.ashx?id=' + this.model.get("id");
and just use a GET
rather than the POST
I originally thought.
The only problem with this approach is that I cant gracefully fail if the file isnt found. So my question now is:
What, inside the XHR
object, is equilvent to Tim's answer? Basically, all I want to do is begin the download. Ive tried:
document.location.href = xhr.getAllResponseHeaders();
But that obviously doesnt work. Any ideas?
You can first make an AJAX request to see if the page will return a 404 error or not. This creates performance and bandwidth issues though.
This question has answers with the implantation details: How can I check existence of a file with JavaScript?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.