Download xhr file
This url must be set, on my example I am assuming you know this part. Also, consider the headers needed for your request to work. Joao Marcos solution works for me but I had to modify the code to make it work on IE, below if what the code looks like. This solution is not very different from those above, but for me it works very well and i think it's clean. Your needs are covered by window. But I am referring to a page that must first be processed and then downloaded.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 7 years, 11 months ago. Active 7 months ago. Viewed k times. Thank you in advance. Improve this question. This will not work, see [this question][1].
Do location. When you need this, it does feel like it's a common thing to ask for, and sadly with no elegant solutions. Add a comment. Active Oldest Votes. Original answer You can't have an AJAX request open the download prompt since you physically have to navigate to the file to prompt for download. Improve this answer. Community Bot 1 1 1 silver badge. Steven Lambert Steven Lambert 5, 1 1 gold badge 26 26 silver badges 44 44 bronze badges.
Doesn't this call the link twice? I'm in a similar boat I'm passing a lot of security information in headers, and able to parse the file object in the success function, but don't know how to trigger a download prompt. It does call the page twice, so if you are querying a database in that page, this means 2 trips to DB. Let me explain how this helped me I have an ajax function that does some error checking on a form submission and then creates a csv file. If the error check fails, it has to come back with why it failed.
If it creates the CSV it is telling the parent that "go ahead and fetch the file". But it will send request 2 times, that is not proper — Dharmendrasinh Chudasama. Show 4 more comments. Taha I tested this on Edge and it seemed to work. Don't know about IE though. My client doesn't target IE users ;- Am I lucky? You have to find the true address by yourself. How to do that? Follow me. Step 1. Head to the development tool of your browser, such as Chrome, Firefox and the like.
Here Chrome is taken as an example. Step 2. In the develop tool, click Network on the top menu bar. Now, click the play button above the video you want to download. To better find the true address, please wait a while for loading the video. After that, click Type and scroll to find XHR in type. You can see the XHR files refresh. Look at the files name, find some files end with ". They are the really address. Click them, a new window will appear. In the header menu of the new window, you can see a request URL, which we need to copy.
Actually, among these. You should better try M3U8 items first appeared after you click the video play button. Step 3. Now, you get the real URL storing the entire video. After the analyzing and downloading, you can get the entire video. But if not, what you need to do is find and try another URL in step 2. Do not be discouraged, try a few more times and you will get the whole video. By the way, the downloaded files are storied in the Download folder under bin folder.
Now, you have learned how to download streaming videos divided into parts of XHR format videos and you are able to download streaming movies from any site with the same method. Except for streaming videos in XHR format, most videos you have watched on websites can be downloaded with a popular video downloader.
There might be a few reasons you would want to do this kind of trickery, but for me, I was generating a PDF on the server based on the contents of te POST request, and then returning that PDF to the client. The desired experience for the user is just a simple 'Download' button, so even though an asset is being dynamically generated, we want to give the illusion that they're just downloading. Step one is to set up the XHR request in Javascript. For some context, let's imagine a simple HTML form:.
When this form is submitted, we're going to send the form data to the server, and expect a PDF back in return, generated dynamically, which is where the responseType comes in. Great now that we've wired up the submission, let's take a bit of time to talk about what's happening on the server's side.