Can someone please guide me how to get the data from a text file in react js? Usually the data extracted from the API is in JSON format but this time I want to render the data that is in .txt file format.
Asked
Active
Viewed 615 times
0
-
Does this answer your question? [How can I parse through local JSON file in React js?](https://stackoverflow.com/questions/37649695/how-can-i-parse-through-local-json-file-in-react-js) – 0stone0 Aug 02 '21 at 16:13
-
No, it is a JSON file but I have a text file. – xiang Aug 02 '21 at 16:16
1 Answers
1
for you to display a doc text like o told me using simple html and css you can use this exemple:
$(document).ready(function() {
$(".word").fancybox({
'width': 600, // or whatever
'height': 320,
'type': 'iframe'
});
}); // ready
<a class="word" href="//docs.google.com/gview?url=http://www.picssel.com/demos/downloads/Fancybox.doc&embedded=true">Open a Word document in Fancybox</a>

NoobDEV-GBL
- 354
- 3
- 20
-
I am getting this error now. Access to fetch at 'https://example.com/sample.txt' from origin 'http://localhost:3000' has been blocked by CORS policy – xiang Aug 02 '21 at 16:28
-
but i do get JSON data with it when converting to JSON where there is 'text'. – xiang Aug 02 '21 at 16:38
-
-
Yes, I have to work with text file as the data available to me is in text format. Is there any possibility to do it successfully? – xiang Aug 02 '21 at 16:59
-
so the error has now gone with the help of { mode: "no-cors" } but i am getting "undefined". – xiang Aug 02 '21 at 17:01
-
i have edited the code, i'm geting the results really nice from local txt file using the require file, have a look – NoobDEV-GBL Aug 02 '21 at 17:08
-
-
that is ok but we won't be able to play around with that as we can with the JSON data. I mean, like this can we able to show some of the text at some place in the browser and skip the rest just like we do with the JSON data? I hope you understood what i mean? – xiang Aug 02 '21 at 17:48
-
Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/235579/discussion-between-noobdev-gbl-and-xiang). – NoobDEV-GBL Aug 03 '21 at 08:42