You can grab data from here. Instead of saving JSON as a separate variable within the script file, is it possible to create a file pointer, and populate a Tree with one config option? Saving JSON in a variable does the job, but it's quite cumbersome!
You can't use files outside of things like AIR it's a security risk and the sandbox won't allow it. You can of course keep the JSON in an external file and request it through HTTP using a TreeLoader with AsyncTreeNode and preloading children OR simply evaluate the AJAX response yourself.
Related
I have a big json file (+-10mb). I want to load in this json file (myjson.json) in a Javascript function located in a HTML webpage. I found a lot of answers on google that say things like "rename to myjson.js" and add var data = " yourjson" and in your html file include myjson.js and acces the variable data. This is not what I want. I want to load in the JSON file without renaming/altering it and without a webserver (No AJAX).
Can anyone help me?
$.getJSON('myjson.json', function(myjson) {...}
Will not work.
Including css and js functions is so easy why is it so impossible to access a locally stored json file without a webserver?
Edit: json file first lines
[{"participants": ["a", "b"], "conversation": [{"sender": "b", "created_at": "2019-09-23T22:04:42.083698+00:00", "text": "xxx"},
Edit: adding my js for clarification
Edit: Can't because I'm on mobile and code formatting doesn't work here
Unfortunately, both XHR and the Fetch API are inextricably tied to HTTP, and cannot be used to load a resource from a relative path unless an HTTP server is involved. If you're loading your page via a file: URL, you won't be able to use XHR or Fetch to get that data.
There are only two methods available to you:
Switch to JavaScript instead of regular JSON and use a <script> tag (as previously suggested to you in another answer)
Allow the user to drag/drop the JSON file (or use <input type="file">) to get a File reference that you can then load.
I think you are looking for FileReader: https://developer.mozilla.org/en-US/docs/Web/API/FileReader
If you have it working, take a look at JSON.parse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
I need to store a file pairing colours and images for use in my JavaScript. I would have liked to use a simple CSV file and Papa Parse, but PP requires either text or a File object as input, and I can find no way of opening a File object, nor of reading the text from the CSV file. Surely my code should be allowed to read files that reside under the web site, not randomly among the file system?
My alternative is to have the end user, non-technical, edit a JSON file that is parsed by my code.
Am I wrong, or is this the case? Then maybe I should build an editor for the JSON file that simplifies the data editing for the end user.
All the file has to store is colour/image name pairs.
Have you tried using something like this? Are you getting an error? Sorry, I cannot leave comments yet.
StreamWriter _testData = new StreamWriter(Server.MapPath("~/data.txt"), true);
_testData.WriteLine(TextBox1.Text); // Write the file.
_testData.Flush();
_testData.Close(); // Close the instance of StreamWriter.
_testData.Dispose(); // Dispose from memory.
I have a Python program that generates an html page for reporting results. The html page is saved in an output directory on disk alongside a javascript file that helps with dynamic table handling. I also save a JSON file to this output directory that I would like to read in with my javascript file. This JSON file has data from the Python run (saved dictionary) that I would like to be able to access. So in an output directory on disk I have:
C:/somedirectory/output/report.html
C:/somedirectory/output/tables.js
C:/somedirectory/output/data.json
All files have been created from my program.
My html page has a table with checkboxes and if those checkboxes are selected I would like to update a second table based on data saved in the JSON file. Thus I would like to open my html report in any browser and read in the JSON file as a javascript object.
I have been trying to use ajax and .getJSON but am getting the
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
I have searched and seen many similar problems but have not come across anything that quite fits what I need. Thoughts and a work around would be greatly appreciated. Thanks.
Update
Since everything is run locally on the client side I have decided to embed the JSON data (python dictionary) and javascript code directly into the html report output. This way the data is internally accessible and the html file can be passed around without dependency issues. The user with the answer I selected below has a link that eludes to this solution.
JavaScript runs on the client machine, hence it can only access files on the client machine using a special setup.
If you want it to read JSON on your server, you should use the path:
http://example.com/output/data.json
Better way would be to read/write JSON file from Python and then send the table data to JavaScript as in this answer: Send data from Python to Javascript (JSON)
I've got a llist of videos, with a click on a name it should display a video, the video-player i'm using read the video file name from a XML document in the same folder, I was thinking in, change the name of the file with javascript in the xml when a video name is clicked but I think this would change the original XML from the server and make it imposible for two people to view the page at the same time which actually sucks.
So is there any way to change only the XML on the user computer?
Or is there another way you can think to acomplish this job?
You can't change a (xml) file on the server easily. When you load it, the server will send you a stream of characters (call it string), which the browser will parse into a Document Object Model. This model is obvious locally, and when you modify it by using DOM manipulation methods like setAttribute, no one else will be affected.
To change a file on the server, you would need to explicitly request the server to do that.
I'm just beginning with JavaScript and I was wondering if I can access a JSON file on the localhost without the use of any servers (like WAMP). I was planning to just read the contents of a JSON file and reflect its contents to an HTML file.
Short answer, yes you can.
Make an XMLHttpRequest against a static file such as: resources/myJSON.json (the extension is merely for organization, you can call the file whatever you want really).
Parse the response as JSON.
Obviously the file must contain a properly formatted JSON object of data, but as long as that's the case, you can load static JSON from a file to "simulate" remote connectivity to a server.
When you're browsing a file as: file:// on your system, it should treat the relative paths correctly.