gpt4 book ai didi

json - 从 Flask 后端获取对 Angular 的 JSON 响应

转载 作者:行者123 更新时间:2023-12-03 17:36:44 29 4
gpt4 key购买 nike

我想从 Flask 后端获取到 Angular 应用程序的 JSON 响应,但找不到错误所在。返回的 JSON 响应是:

{
"phones": [
{
"age": 0,
"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S."
},
{
"age": 1,
"name": "Motorola XOOM with Wi-Fi",
"snippet": "The Next, Next Generation tablet."
},
{
"age": 2,
"name": "MOTOROLA XOOM",
"snippet": "The Next, Next Generation tablet."
}
]
}

这是 Controller :
function Phones($scope, $http){
$http.get('127.0.0.1:5000/phones').success(function(data){
$scope.phns = data.phones;
console.log("I'm called");
});
}

当我像这样将 JSON 对象传递给 Controller ​​时,这有效:
$scope.phones = [
{"name": "Nexus S",
"snippet": "Fast just got faster with Nexus S.",
"age": 0},
{"name": "Motorola XOOM with Wi-Fi",
"snippet": "The Next, Next Generation tablet.",
"age": 1},
{"name": "MOTOROLA XOOM",
"snippet": "The Next, Next Generation tablet.",
"age": 2}
];

当我尝试获取 data.phones 之类的数据时,它也不起作用。我确定 Controller 会被调用,但 get 函数不会以某种方式获取数据。

最佳答案

将“http”添加到 127.0.0.1:5000/phones 应该可以解决问题。

关于json - 从 Flask 后端获取对 Angular 的 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17660675/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com