【发布时间】:2017-02-26 07:31:57
【问题描述】:
我正在尝试从 URL(例如 SOMEURL/ean.php?id=4001513007704)获取 JSON-Text-Stream。结果如下所示:
{
"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>
这不是(变量留空)。在这种情况下,我使用 Google,但通常我们会使用其他来源!
<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 中获取数据?有什么解决方法吗?
感谢您的任何帮助!
【问题讨论】:
-
已经投票关闭。
标签: javascript html angularjs cordova ionic-framework