javascript - JS从flask中获取返回0数组长度
问题描述
我有一个非常简单明了的代码:
派:
@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;
})
然而我得到:
我不确定这是为什么。
解决方案
我不确定您的 Python 代码,但fetch
在 js 中,您需要json
先将响应转换为。
这应该有效:
fetch('/Ajax')
.then(response => response.json()) // <--- this has been added
.then(function (response) {
theData = Object.values(response);
console.log(theData);
return theData;
});
推荐阅读
- c# - 确定站点正在使用的 Angular/AngularJS 版本的最快和最好的方法是什么?
- ios - 如何在 Iphone 上设置不透明动画?
- javascript - Selenium 不会点击最上面的元素
- php - PHP/Laravel 只检查一次函数中的条件
- javascript - 返回 null 的对象数组
- javascript - 当数字达到一定范围时,它会回到以前的数字
- image - 在同一个图像张量上使用 torchvision.utils.save_image 两次会使第二次保存不起作用。这是怎么回事?
- sql - SSIS 包失败。“清理失败。为 Web 服务创建的代理可能尚未删除。”
- typescript - 扩展 BehaviorSubject 的只读存储
- amazon-rds - 在 RDS 实例上运行 pt-osc 以更改具有 19 亿条记录的表