我试图从URL获取JSON文本流(例如SOMEURL/ean.php?id = 4001513007704)。结果是这样的:通过AngularJS从外部URL获取文本
{
"product": {
"ean_id": "4001513007704",
"title": "Gerolsteiner Mineralwasser",
...
},
"success": true
}
正如你所看到的这些都是扫描的项目的一些信息。 我搜索了使用URL的实现( - >http://www.w3schools.com/angular/tryit.asp?filename=try_ng_http_get),本示例仅适用于内部URL。 Google和其他来源将变量留空。
这是行不通的。它返回的HTML代码输入网站:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<p>Today's welcome message is:</p>
<h1>{{myWelcome}}</h1>
</div>
<p>The $http service requests a page on the server, and the response is set as the value of the "myWelcome" variable.</p>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/default.asp")
.then(function(response) {
$scope.myWelcome = response.data;
});
});
</script>
</body>
</html>
这并不(可变留空)。在这种情况下,我使用谷歌,但通常我们会使用其他来源!
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope, $http) {
$http.get("http://google.com/")
.then(function(response) {
$scope.myWelcome = response.data;
});
});
</script>
我认为这是因为从网站的安全设置..
如何我可以从URL中的数据?有什么解决方法吗?
感谢您的任何帮助!
已经投票决定关闭。 –