Can we link a Variable Arrays from external source? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we link a Variable Arrays from external source?

Is it possible if i write some sort of variable arrays in a txt file and save it on some cloud storage and call it into JS script? if yes, then how do i do that? thanks all 😊

29th Apr 2020, 1:37 PM
Ridzuan Wan
Ridzuan Wan - avatar
10 Answers
+ 3
Surely you can. But the extension of the file must be 'js'. You can write any valid javascript code in a file. Then upload it to dropbox or any other hosting site. Therefore, you can now load the script using the 'script' tag.
29th Apr 2020, 4:52 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 3
Where is your attempt? Please try to do that, then can you more quickly learn the language and come to a solution of your task.
29th Apr 2020, 4:55 PM
JaScript
JaScript - avatar
+ 2
Arb Rahim Badsa you're almost right, except for a tiny details: file extension must be 'js' or also often 'json' if file is served "automatically" (then the MIME type of the send file is set according to its extension), but if you handle it "manually" you could serve file with any extension you want since you set the correct js MIME type for the Http request response ;)
29th Apr 2020, 5:16 PM
visph
visph - avatar
+ 2
Arb Rahim Badsa on server side with almost any web framework, you could set response headers as you want, among wich information is the MIME type of the file you send to client side (used by browser to know what kind of ressource it is and what to do with it, not relying only on the file extension ;)) https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
29th Apr 2020, 5:27 PM
visph
visph - avatar
+ 1
Thanks Arb Rahim.. actually I tried it once before but not working, will give another shot and see, maybe i will paste the code here as well later 😜
29th Apr 2020, 4:59 PM
Ridzuan Wan
Ridzuan Wan - avatar
+ 1
Sure, you can attach the code here. Perhaps I'll then be able to show you a demo.
29th Apr 2020, 5:00 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
Ohmyyy... It works now 😄 thanks you guys for your guidance.. I upload my variable js file into GDrive.. thanks again! 😊😊 https://code.sololearn.com/WhjXN1IRQky0/?ref=app
29th Apr 2020, 5:12 PM
Ridzuan Wan
Ridzuan Wan - avatar
+ 1
visph That was indeed a good information. But what do you actually mean by handling 'manually'?
29th Apr 2020, 5:20 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 1
You can but in HTML add script with array first and then script which uses this array
30th Apr 2020, 9:26 PM
Bartek Wilk
Bartek Wilk - avatar
0
Ok Sir, thanks so much! 😊, I still have alot more to study in.. wish me succeed.. 😂LoL
29th Apr 2020, 5:21 PM
Ridzuan Wan
Ridzuan Wan - avatar