Javascript download json file of actions
I prefer pure JS over jQuery syntax. Today's test in Edge: data. While this is a great answer, initMouseEvent is a deprecated Web Standard and should not be used anymore. Instead, use the new MouseEvent interface. It's just a minor refactor though. Thanks, only one that didn't give me size issues — Roelant. Hope this helps someone. Fabian von Ellerts 3, 31 31 silver badges 32 32 bronze badges. Brad Brad 6, 7 7 gold badges 31 31 silver badges 44 44 bronze badges.
This worked on Chrome, but doesn't seem to work on Firefox Nice function, add document. Mohammed H 6, 13 13 gold badges 73 73 silver badges bronze badges. I believe you should clean link after you're done with it, by calling link. Thank you! Nam Do Nam Do 33 7 7 bronze badges. Sorry for coming back to you late. I tried your answer and it does download file but contains wrong data in it..
React : add this where you want in your render method. Abido Abido 5 5 silver badges 18 18 bronze badges. If you prefer console snippet, raser, than filename, you can do this: window. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Who is building clouds for the independent developer? Exploding turkeys and how not to thaw your frozen bird: Top turkey questions Show 6 more comments. Community Bot 1 1 1 silver badge. SpoonHonda SpoonHonda 2 2 silver badges 5 5 bronze badges. You didn't understand either what "local file" means in the question: not HTTP.
It works like a charm and the explanation is also correct! I'm surprised import from es6 has not been mentioned use with small files Ex: import test from '. Ogglas Ogglas You cannot use the es6 import statement when the webpage is loaded with the file: protocol.
Recently D3js is able to handle local json file. TechSpud TechSpud 3, 1 1 gold badge 19 19 silver badges 31 31 bronze badges. This does not seem very reusable. For example, if the json file is served by a remote server, ms timeout may not be enough for load. And as the time depends on the client's connection speed, you would have to set a very long timeout for clients with slow connection. In short, setTimeout should not be used to wait for loading of a resource.
Kenny - It's meant to solve a specific problem - loading local resources for a non-hosted web page , so that does mean it's not very reusable. There are 's of resource loading solutions for web-hosted pages. This is not the solution, it's a solution. It's really simple to change the timeout. By removing the timeout, are you suggesting that an infinite wait is acceptable?
I'm not suggesting an infinite wait, I'm suggesting using a technique that allows you to react to file load as soon as it is finished.
My problem with timeout is, that you always have to wait for it to finish. Even if the file would have loaded in 10ms, you would still wait for ms. And yes, adjusting timeout is easy, but what you are suggesting is changing the code each time you want to load a different file or when the file siize changes to optimize the wait.
Such a solution is IMHO wrong and can cause a lot of headaches in the future, especially when someone else tries to use it. Anyone using this script should use it as a basis for their own scripts. You're entitled to your opinion on whether this script is wrong. Why not suggest an alternative solution? This definitely won't work for all use cases. It worked for me, loading a local file from a local html page. I shared my solution on this question, in the hope it would help someone else.
Are you trying to load a local resource? Why not pass in the timeout value as a variable, based on the file you're loading? Ajax on local files is pretty limited. You may be better off using onreadystatechange or onload and giving them a function. For example loading a font. May write with more details because the answer is a bit unclearly understandable. This requires transpiling TypeScript to JavaScript.
Supun Kavinda Supun Kavinda 10 10 silver badges 13 13 bronze badges. Works perfectly in Chrome and without any additional libraries. Mark Mark 3 3 silver badges 16 16 bronze badges. In angular or any other framework , you can load using http get I use it something like this: this. As an example: console. Epiphany Epiphany 1, 1 1 gold badge 18 18 silver badges 14 14 bronze badges. Victor Stoddard Victor Stoddard 3, 2 2 gold badges 23 23 silver badges 23 23 bronze badges.
Himanshu 4, 16 16 gold badges 28 28 silver badges 37 37 bronze badges. Karhan Vijay Karhan Vijay 19 3 3 bronze badges. This is a different piece of code when compared with other answers. Manse Manse 37k 9 9 gold badges 79 79 silver badges bronze badges. Yes, but how do you load a local JSON file?
This doesn't really answer the question. Stefan read the bottom sentence - you cant — Manse. So just to complete the list for future vistors, here's how you load a JSON from local file with Closure library: goog. Kenny Kenny 4 4 silver badges 8 8 bronze badges. Jeeva Jeeva 1, 1 1 gold badge 13 13 silver badges 18 18 bronze badges. Embedding the JSON data in the script is not the question asked.
FileSystemObject" ;; if fso. Feng Zhang Feng Zhang 1, 10 10 silver badges 18 18 bronze badges. Please explain your solution instead of just pasting the code. Only a solution explaining how it solved the problem will help the community. Note: Requires InternetExplorer — Sancarn.
Bishwas Mishra Bishwas Mishra 1, 10 10 silver badges 24 24 bronze badges. Add Comment. Disclaimer : The code samples and API available at www. You are free to use it for commercial as well as non-commercial use at your own risk, but you cannot use it for posting on blogs or other tutorial websites similar to www. All the code samples and API provided by the authors are solely their creation and neither the author nor the site are responsible if it does not work as intended.
I agree to the above terms. Download Required. View Demo. What our readers say. Error Details. This site makes use of Cookies. Please refer Privacy Policy for more details.
0コメント