【发布时间】:2016-10-28 12:00:43
【问题描述】:
我试图从 JSON 范围之外的 JSON 中获取国家/地区名称,但不知何故它似乎没有通过,我做错了什么?我查看了 $rootScope 但似乎并没有走得太远。原则上很简单,我想在其他作用域或页面本身上使用Country name作为变量,也想在Controller.cs(.net)中使用它发送到数据库
app.controller('PageController',
function ($scope, $http) {
var analyticsCountry = "default";
$.getJSON('//www.geoplugin.net/json.gp?jsoncallback=?',
function (data) {
$scope.testing = data;
$scope.testing.country = data.geoplugin_countryName;
//console.log($scope.testing.country);
analyticsCountry = $scope.testing.country;
});
console.log(analyticsCountry);
$scope.GetTrendingCDsByCountry = function () {
$http({
method: 'Get',
url: "/CD/GetTrending?id=" + analyticsCountry
})
.success(function (data, status, headers, config) {
$scope.cds= data;
})
.error(function (data, status, headers, config) {
$scope.message = 'Unexpected Error';
});
};
});
【问题讨论】:
标签: javascript angularjs json http geolocation