Please tell me how to get it in the form of JSON on API fetch.

Asked 1 years ago, Updated 1 years ago, 24 views

In the case of text().then(), the string can be retrieved successfully, but when I try to retrieve it with data, the following error appears:

I'd like to loop with the JSON I got and make an id price table...

error messages:

 calendar:164 Uncaught (promise) TypeError: response.data is not a function
    at masako —164
(anonymous) @masako:164

source code:

var url=$url+"?date="+param(value);
let myFetch=fetch(url);
myFetch.then(function(response){
    console.log(response);
    response.text().then(function(text){
        If there is no // data, text can retrieve it successfully.
        // [{"id":25, "price":300}, {"id":27, "price":400},});
        response.data().then(function(data){
        });

javascript

2022-09-30 16:33

1 Answers

This is helpful.

https://developer.mozilla.org/ja/docs/Web/API/Fetch_API/Using_Fetch

Quote:

 fetch('http://example.com/movies.json')
  .then(response=>response.json())
  .then(data=>console.log(data)));

Therefore, I think it will be as follows.

let myFetch=fetch(url);
myFetch
    .then(response=>response.json())
    .then(data=>console.log(data)));


2022-09-30 16:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.