I need to load multiple different JSON files.Now I use many AJAX to load them one by one, according to a list of their file name. But if I add a new JSON, I should change the list by myself. How can I load JSON files with code automatically?
solution 1:
A possible solution is to create a JSON file that contains all file names. Then you just have to update the JSON file instead of the list.
solution 2:
In the case where the file names are like file1.json, file2.json, ..., you can try to get them with a loop and leave it at the first AJAX resource not found exception.
Related
I'm having a file which contains a couple of space separated (or comma separated, it will be editable) serial-numbers (all unique).
Now through my Oracle APEX I get one serial-number. My goal is to check if this serial code which could be passed on to a parameter of obtained through $v('P#_SERIAL_ID') is equal to one of the serial-numbers in the file.
Is this even possible within Javascript? If so, is there an existing function/code to achieve my goal?
Stackoverflow questions that didn't help me but look alike:
Javascript-read-file-contents
C#-reading-and-editing-file
Java-string-comparison
You can do this without JavaScript. Import your file into Apex through an Data Load Wizard Page so you will have the content of your file into a table. This way you can compare your information through some kind of SQL validation.
If you don`t like the Data Load Wizard Page you can add a file browse item on a simple page that will take your file and save it as a blob into the database. From there you can again process the file and compare the values.
I want to convert the plaintext Public Suffix List to JSON object so as to use it in my script. I just want the list of TLD's.
The list is here https://publicsuffix.org/list/effective_tld_names.dat
My initial thought was to regex match the file for suffix list but I don't know how to regex files in javascript. I'm kind of new to javascript.
Anyone having idea, how to achieve this. Thank You
First off, the list doesn't seem to be allowed to do cross-domain, so direct AJAX to the resource isn't possible.
What you can do is have your server load it for you (PHP: file_get_contents, JS: http.get). Then, implement a parser. I'm not familiar with the format of the file, but you can read the file line by line, skip blank lines and lines with //. Then load them into an array (PHP: array_push, JS: Array.prototype.push), serialize (PHP: json_encode, JS: JSON.serialize) and ship as JSON to your app.
I have a list of images and an HTML string which holds a web page containing the images. I would like to create a zipped file via JavaScript code by using zip.js and save it at runtime.
The creation of the htmlString to file.html was easy, but I'm not sure on how I can send this list of images to zip.js.
I thought to create dynamically via JavaScript a list of input file elements maybe via jQuery or something, but I still cannot figure out how to do it. Does there exist some way to do that?
If I understand correctly, you managed to create the list of files (array?) and your issue is to create the zip file that contains the files.
If this is the case you can try using this small package :
https://www.npmjs.com/package/list-to-zip
It accept an array of urls and create a zip file from it.
Is it possible to use Javascript to list all the files contained in a subfolder?
I have a bunch of images that need to be linked too, but I would like it to be dynamic because the list will be changing a lot.
Thankyou!!!
Is it possible to use Javascript to list all the files contained in a subfolder?
No. You would usually set up a simple server side script that does the listing (e.g. using PHP's glob()), and output a JSON array, for example.
I have some jQuery code which retrieves content using getJSON().
There are n JSON files, which are retrieved from the server as needed:
/json-content/data0.json
/json-content/data1.json
/json-content/data2.json
etc...
Instead, I want to store all the JSON in a single file to reduce the number of HTTP requests needed to retrieve the data.
What is the best way to combine the JSON files into one?
If I concatenate the JSON files together, it no longer works with getJSON().
UPDATE - clarified my question
Either as individual attributes or as an array
{
"data1":{stuff for data1},
"data2":{stuff for data2},
"data3":{stuff for data3}
}
or
{"response":[
{stuff for data1},
{stuff for data2},
{stuff for data3}]}
If you really want to reduce the number of HTTP requests from the client, one possible way is like this:
Build a server side proxy that get JSon files from the third party data sources
Merge your 3 JSon files in one single JSon file
Make a single $.getJSON() call to your single JSon from client
To merge Json files, look at this post.