I'm trying to get the JSON-Text-Stream from an URL (e.g. SOMEURL/ean.php?id=4001513007704). The result looks like this:
{
"product": {
"ean_id": "4001513007704",
"title": "Gerolsteiner Mineralwasser",
...
},
"success": true
}
As you can see these are some informations for scanned items. I searched for implementations using URLs (--> http://www.w3schools.com/angular/tryit.asp?filename=try_ng_http_get ) and this example only works for the internal URL. Google and other sources leave the variable blank.
This does work. It returns the HTML-Code of the entered website:
<!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>
And this doesn't (variable is left blank). In this case i use Google but usually we would use another source!
<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>
I assume that it's because of the security settings from the website..
How can i get the data from the URL? Is there any workaround?
Thanks for any kind of help!