从AngularJS HTTP状态0获取JSON [英] HTTP Status 0 from AngularJS Get for JSON
问题描述
我运行一个$ http.get的JSON和我得到的0状态,我用请求库下载相同的JSON和获取本地工作,并在Python中我可以得到JSON没有问题,但在AngularJS它不工作。我不明白的是为什么角没有得到它,但一切是。低于code片段。
I'm running a $http.get for a JSON and am getting a status of 0. I've downloaded the same JSON and the get works locally, and in Python using the requests library I can get the JSON no problem, but in AngularJS it's not working. What I don't understand is why angular isn't getting it but everything else is. Code snippet below.
function AgentListCtrl($scope, $http) {
$http.get('http://foo.bar/api/objects').success(function(data) {
$scope.objects = data;
}).error(function(data, status) {
$scope.status1 = status;
});
这提供了JSON和使用本地文件时分析它,但除此之外,它失败,并设置STATUS1为0。
This provides the JSON and parses it when using a local file, but otherwise it fails and sets status1 to 0.
推荐答案
在您的code,状态分配在发生错误时才会出现。你应该能够得到当调用成功了这样的状态:
In your code, the status assignment only occurs when the error happens. You should be able to get the status when the call was made successfully like this:
success(function(data, status, headers, config) {
$scope.objects = data;
$scope.status1 = status;
}).error(function(data, status) {
$scope.status1 = status;
});
这篇关于从AngularJS HTTP状态0获取JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!