error message I am trying to access a local .json file using fetch() like
fetch('fakedata.json')
.then((res) => res.json())
.then((data) => {
console.log('data:', data);
})
But when i saw in the network it is showing
You need to enable javascript to run this app
I check in some other pages but i cant fix this issue. How to fix this issue
To disable it, or check it is enabled, type about:config in the URL field and confirm that you are not scared of dragons. Search for JavaScript:enabled . If it says true in the right hand column, JS is enabled. To change the setting, click on it and then click Toggle.
I am not sure what you mean by trying to access a local json file. You can not access files on the device that runs the webpage if that is what you mean by local files. You can only access to files that are on the webserver that is serving your applications which are in directory of your application. I assume the second case and assume you have file called fakedata.json at the top directory of your application. In order to access that file you can use import as following:
import myJsonFile from "./fakedata.json"
If you want to use fetch to dynamically load, you should put ./ at the beginning as
fetch('./fakedata.json')
so that it fetches a file called fakedata.json which is located at the root directory.
I was facing similar issues.
I had put the below code just after app.use
app.get('/*', (req, res) => {
res.sendFile(path.join(__dirname, '/../', 'build', 'index.html'));
});
which served all the API requests directly.
Maybe this can help others facing this issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With