猿问

JS fetch 从 Flask 返回 0 数组长度

我有一个非常简单明了的代码:


py:


@blueprint.route('/Ajax', methods=['GET', 'POST']) 

def Ajax():                

    Graph1 = [10,10,10,10,10]

    return jsonify(Graph1)

JS


fetch('/Ajax')

.then(function (response) {

  theData = Object.values(response); 

  console.log(theData);

  return theData; 

})

但我得到:

我不知道为什么是这个原因。



拉莫斯之舞
浏览 97回答 1
1回答

牛魔王的故事

我不确定你的Python代码,但在fetchjs中你需要首先将响应转换为json。这应该有效:fetch('/Ajax')   .then(response => response.json())  // <--- this has been added   .then(function (response) {     theData = Object.values(response);      console.log(theData);    return theData;    });
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答