将String范围变量作为参数传递给AngularJS中的$ http.get

时间:2015-04-12 16:31:49

标签: angularjs angularjs-scope

给定代码中的http请求语句有什么问题:

$scope.s ="api.openweathermap.org/data/2.5/weather?q=pilani,in";

 $http.get($scope.s)
.success(function (data)
{       
alert("temp");
    angular.element('#temperature').scope().temp = data;
    angular.element('#temperature').scope().$apply();
});  

此http请求无效。

1 个答案:

答案 0 :(得分:0)

您错过了网址的协议部分。当您将没有协议的网址传递给$http.get(或更常见地传递给XMLHttpRequest.open)时,会将其视为当前路径的相对网址。

http://添加到URL的开头,它应该按预期工作,因为服务器允许跨源请求。请注意,由于此服务器不安全,因此用户可能会获得混合内容"如果您从https://地址发出这些请求,请发出警告。

相关问题