Javascript download ajax response as xml file
Official website: msdn. Official website: adobe. See also: Adobe Systems. Official website: aws. Official website: camel. See also: Apache , Design Pattern. Official website: cassandra. See also:. NET , WebMatrix. Tools: WolframAlpha. Official website: www. See also: Cloud Computing , Windows. Official website: oracle. Official website: catalystframework. See also: Erlang , Haskell. See also: Design Pattern , Mathematics.
Official website: eclipse. Official website: java. See also: Clojure , Haskell. Official website: F at Microsoft Research. See also: Red Hat , Linux , rpm. Official website: git-scm. Official website: golang. Official websites: www. Official website: haproxy.
Blog: haproxy. See also: Clojure , Erlang. Official website: hbase. See also: Adobe Systems , Illustrator , Photoshop. Official website: inkscape. Official website: openjdk.
See also: Java , Silverlight. See also: Java , RichFaces , Seam. Official website: julialang. Official website: kubernetes. Official website: vim-latex. Official website: ibm. The downside is that the underlying network connection could timeout waiting for data to start flowing either on the client or server side. I wrote a simple JavaScript class that implements a technique similar to the one described in bulltorious answer. I hope it can be useful to someone here.
The GitHub project is called response-monitor. By default it uses spin. For more examples check the examples folder on the repository.
If you're streaming a file that you're generating dynamically, and also have a realtime server-to-client messaging library implemented, you can alert your client pretty easily. The server-to-client messaging library I like and recommend is Socket. After your server script is done generating the file that is being streamed for download your last line in that script can emit a message to Socket. On the client, Socket. The benefit of using this method over others is that you are able to detect a "true" finish event after the streaming is done.
For example, you could show your busy indicator after a download link is clicked, stream your file, emit a message to Socket. I realize most people reading answers to this question might not have this type of a setup, but I've used this exact solution to great effect in my own projects and it works wonderfully.
My solution with a cookie: - Client side: When submitting your form, call your javascript function to hide your page and load your waiting spinner. If the cookie is found, stop checking every ms, expire the cookie and call your function to come back to your page and remove the waiting spinner removeWaitingSpinner.
It is important to expire the cookie if you want to be able to download another file again! That cookie will be sent to the client when your file will be ready for download. I'm very late to the party but I'll put this up here if anyone else would like to know my solution:. I had a real struggle with this exact problem but I found a viable solution using iframes I know, I know. It's terrible but it works for a simple problem that I had. I had an html page that launched a separate php script that generated the file and then downloaded it.
On the html page, i used the following jquery in the html header you'll need to include a jquery library as well :. To break this down, jquery first launches your php script in an iframe. The iframe is loaded once the file is generated.
Then jquery launches the script again with a request variable telling the script to download the file. The reason that you can't do the download and file generation all in one go is due to the php header function.
If you use header , you're changing the script to something other than a web page and jquery will never recognize the download script as being 'loaded'. I know this may not necessarily be detecting when a browser receives a file but your issue sounded similar to mine. When the user triggers the generation of the file, you could simply assign a unique ID to that "download", and send the user to a page which refreshes or checks with AJAX every few seconds.
Once the file is finished, save it under that same unique ID and If you don't want to generate and store the file on the server, are you willing to store the status, e. Your "waiting" page could poll the server to know when the file generation is complete. You wouldn't know for sure that the browser started the download but you'd have some confidence.
I just had this exact same problem. My solution was to use temporary files since I was generating a bunch of temporary files already. The form is submitted with:. This will cause the load event on the iframe to be fired. Then the wait message is closed and the file download will then start. Tested on IE7 and Firefox. If you have download a file, which is saved, as opposed to being in the document, there's no way to determine when the download is complete, since it is not in the scope of the current document, but a separate process in the browser.
BUT onload does not fire in IE for file downloads like with the attachment header token. Polling the server works, but I dislike the extra complexity. So here is what I do:. But really, if your sites that busy the long running process will starve you of threads anyways.
A quick solution if you only want to display a message or a loader gif until the download dialog is displayed is to put the message in a hidden container and when you click on the button that generate the file to be downloaded you make the container visible. Then use jquery or javascript to catch the focusout event of the button to hide the container that contain the message. If Xmlhttprequest with blob is not an option then you can open your file in new window and check if eny elements get populated in that window body with interval.
Then the server-side overrides this cookie with an earlier expiration age -- the completion of the server process. As soon as the cookie expiration is detected in the JS polling, "Loading You can rely on the browser's cache and trigger second download of the same file when the file is loaded to the cache.
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. Detect when browser receives file download Ask Question. Asked 12 years, 4 months ago.
Active 3 months ago. Viewed k times. Does anyone have a better idea? Riyaz Khan 1, 7 7 silver badges 21 21 bronze badges. Thanks Eric -- that's good to know. I won't waste any more time with that approach. From the command prompt we can simply invoke live-server within the new folder.
The following code is the complete client-side logic. We then attach an event handler to the click event of the element with the ID get-data. Besides converting parts of the object to an unordered list, the full object is also stringified and displayed on the screen.
Of course, for our example the data is fixed, but in general any kind of response is possible. Therefore, the callback will be executed at some unknown later point in time. The sample JSON file is much larger than the subset we care about. Nevertheless, the sample has been constructed in such a way as to show most of the JSON grammar.
This provides a software- and hardware-independent way of storing, transporting, and sharing data. XML also makes it easier to expand or upgrade to new operating systems, new applications, or new browsers, without losing data. With XML, data can be available to all kinds of "reading machines" like people, computers, voice machines, news feeds, etc. We just launched W3Schools videos. Get certified by completing a course today!
0コメント