Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  48] [ 4]  / answers: 1 / hits: 27667  / 9 Years ago, wed, may 6, 2015, 12:00:00

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.


More From » html

 Answers
51

Try using .then() as described here:



fetch('URL/out.json', {mode: 'cors'}).then(function(response) {
return response.blob();
}).then(function(response) {
// process response
});

[#66718] Tuesday, May 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
trinityr

Total Points: 49
Total Questions: 107
Total Answers: 96

Location: Mayotte
Member since Fri, Oct 1, 2021
3 Years ago
;