【发布时间】:2019-01-20 06:27:56
【问题描述】:
我目前正在做前端,后端使用 python。前端是 html,我使用 angularJs 进行通信。
我的问题是我无法从 python 后端获得响应,虽然它被正确调用,但生成了一个列表,我将结果写如下(在我的 python 代码中)
self.write({"success":True, "data":list})
但是,角度代码没有收到任何响应。只返回成功(http 200OK)状态码。如何让后端成功发送列表作为响应?
顺便说一句,角码是
$scope.init = function () {
//Take the list of applications from database
var req = {
method: 'GET',
url: 'http://localhost:8888/app',
headers: {
'Content-Type': "application/json;charset=UTF-8"
}
}
$http(req).success(function(data) {
$scope.results = response.data
// response is undefined??
} )
.error (.......);
【问题讨论】:
-
也许试试 console.log(data)?它现在看起来如何响应将是未定义的,因为您只是从函数中获取数据。基本上 .success(function(response)) 与您所拥有的 .success(function(data)) 之间的区别
-
Console.log 给了我 -> 可能未处理的拒绝:{"data":null,"status":-1,"config":{"method":"GET","transformRequest": [null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"localhost:8888/app","headers":{"Accept":"application/json, text/plain, / i>"}},"statusText":"","xhrStatus":"error"}
-
用函数(响应)替换你的函数(数据),因为现在响应是未定义的,因为它实际上没有在任何地方传递或在任何地方初始化。
-
仍然未定义,控制台给出相同的输出
-
也许看看这个codelord.net/2015/05/25/dont-use-%24https-success。显然,更好的方法是使用 .then() 表示法,所以也许可以研究一下。
标签: python angularjs frontend backend