I am using FETCH API to get a value stored in a json file. That value has to go into a variable.
The problem is - the variable ends up holding [object Object] as value.
var title = fetch('URL/out.json', {mode: 'cors'});
In the htaccess of the server hosting the json file, there is the line
Header set Access-Control-Allow-Origin "*"
The json is as follows
{
lollol
}
I think the json might be the culprit.
I cannot find the reason for [object Object] to be the variable value.
Can I use Fetch to get a hosted text file? I tried - couldn't get it work. - just thinking of an alternative.
Try using .then() as described here:
fetch('URL/out.json', {mode: 'cors'}).then(function(response) {
return response.blob();
}).then(function(response) {
// process response
});
you need to stringify the object to convert it into JSON string.
try JSON.stringify(theObject)
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