URLからJSON-Text-Streamを取得しようとしています(例: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やその他のソースは変数を空白のままにします。
これは機能します。
<!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>
をそして、これは(変数が空白のままに)しません:それは、入力されたウェブサイトの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からデータを取得できますか
...それがあるため、ウェブサイトからのセキュリティ設定のだと仮定?回避策はありますか?
ありがとうございました!
示すように、サイト内のリンクhttp://google.com/とW3学校で上記のコードを実行してみてくださいすでに閉鎖して投票しました。 –