0

text().then() の場合は正常に文字列が取得できるのですが、dataで取ろうとすると下記のエラーが出ます。

取得したJSONでループを行い、id priceのテーブルを作りたいのですが…

エラーメッセージ:

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

ソースコード:

var url = $url+"?date="+ param(value);
let myFetch = fetch(url);
myFetch.then(function(response) {
    console.log(response);
    response.text().then(function(text) {
        //dataがない場合 textで正常に取得できます。
        //[{"id":25,"price":300},{"id":27,"price":400},});
        response.data().then(function(data) {
        });

1 件の回答 1

0

こちらが参考になります。

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

引用:

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

なので、下記のようになると思います。

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

この質問に回答するには、ログインする必要があります。

求めていた回答ではありませんか? のタグが付いた他の質問を参照する。