+ 2
[SOLVED] How to read the content of an external text file
How to read external content of a text file to work with as an array or variable? (Something like file_gets_content in PHP) I have 2048 words in my text file on 2048 lines. ((I do not want them converted into a internal array and implement it in my code, but leave them as it is otherwise it takes to much space.. )) I have the .txt file external in my Dropbox and want to read the content with JavaScript. How?! https://www.dropbox.com/s/7of3dozytnlq1tt/words.txt?dl=0
6 Respostas
+ 3
Remember that JS is client side. You can try using iframe (HTML) or try using AJAX.
+ 3
Check this thread:
https://www.dropboxforum.com/t5/API-Support-Feedback/HTTP-request-to-dropbox-APIs/td-p/169597
Here is some info on CORS:
https://www.sencha.com/forum/showthread.php?299915-How-to-make-an-ajax-request-cross-origin-CORS
https://zinoui.com/blog/cross-domain-ajax-request
I highly recommend you to study a bit of TCP/IP, POST/GET and TCP headers before going into AJAX.
+ 2
External link, but this was one of projects i made using AJAX via GET method.
https://codepen.io/ronkiro/pen/QmmPGM
You can use it as an example.
+ 1
Alexander Santos,
I did some reseach to AJAX http requests and found that AJAX is a very good for those tasks. Thanks for that👍.
I made me some code to read the content of the text file but I get an error.
CORS policy is blocking the GET request.. So there is no connection at all after debugging the code...
How to solve the request blocking?
Have a look at the console log after button click:
https://code.sololearn.com/WPp9ZQQThP2b/?ref=app
+ 1
ODLNT & Alexander Santos,
Thank you both for helping me out with AJAX and providing extended information about this subject!! excellent!
I understand now it had nothing to do with my script but with the server I'll try to get requests from. Since I need to work with API credentials at Dropbox I wont implement them in SL. Therefore, Socrata is an very good option to understand more of the basics about API's and the server requests that AJAX provides.
Will get more into this right now!👍
0
ODLNT, Thanks👍