Jump to content

need help with js

Bartb56

Hey guys im trying to make a website where i can upload a json file, this file has a array in it i want to display the array on the page but i have no clue how to let a user select and upload a file

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, Bartb56 said:

Hey guys im trying to make a website where i can upload a json file, this file has a array in it i want to display the array on the page but i have no clue how to let a user select and upload a file

What language are you using for the backend? If you don't plan on using a backend and strictly want to do this client side you'd want to look at the HTML5 file API.

 

https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications

import { signature } from "./signature";

signature.display({ cpu"Intel i9 9900k @ 3.56HZ",  gpu"ASUS GTX 1080",  ram"32GB CORSAIR DDR4", motherboard"ASUS Z390-E" });

 

Link to comment
Share on other sites

Link to post
Share on other sites

Well you could make the JSON accessible via API

mywebsite.com/api/json?id=1

Then in the javascript you can use AJAX to call for that file. check out https://github.com/mzabriskie/axios

Of course if the API isn't needed. You can directly render it to the page with PHP. You could just set the JSON text to a variable in javascript.

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, Ampix0 said:

Well you could make the JSON accessible via API


mywebsite.com/api/json?id=1

Then in the javascript you can use AJAX to call for that file. check out https://github.com/mzabriskie/axios

Of course if the API isn't needed. You can directly render it to the page with PHP. You could just set the JSON text to a variable in javascript.

you mean make the upload part (already did that) then make the fiile a variable and let it load once the guy presses on the upload button?

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×