0

I try to get into angularJS's http.get

I have a simple restful service.

http://groupify-webtechproject.rhcloud.com/api/test/helloworld

will return a "Hello World" plain text. I want to retrieve that with angularjs and and alert it or even better display it on my index.html

But after 2 hours of trying and not getting a step closer maybe one of you can help.

These are my HTML5 and js code snippets:

angular.module('myApp', []).controller('Hello', function ($scope, $http) {
    $http.jsonp('http://groupify-webtechproject.rhcloud.com/api/test/helloworld').
        success(function(data) {
			alert("success");
            alert(data);
            $scope.data = data;
            alert(data);
		}).
		error(function(data, status) {
			alert("error");
			alert(data);
        });
});
<!doctype html>
<html ng-app="myApp">
<head>
    <title>Hello AngularJS</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.1/angular-resource.min.js"></script>
    <script src="main.js"></script>
</head>

<body>
<div ng-controller="Hello">
    <p>{{data}}</p>
</div>
</body>
</html>

1 Answer 1

1

you embedded agular 1.* instead of a newer version. also your resource is not available anymore (404).

other than that, the code works.


angular.module('myApp', []).controller('Hello', function ($scope, $http) {
    $http.jsonp('http://groupify-webtechproject.rhcloud.com/api/test/helloworld').
        success(function(data) {
			console.log('success', data);
            $scope.data = data;
		}).
		error(function(data, status) {
			console.log('error', data, status);
            $scope.data = 'error with status code: ' + status;
        });
});
<!doctype html>
<html ng-app="myApp">
<head>
    <title>Hello AngularJS</title>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-resource.min.js"></script>
</head>

<body>
<div ng-controller="Hello">
    <p>{{data}}</p>
</div>
</body>
</html>

Sign up to request clarification or add additional context in comments.

1 Comment

figured it out. Everything was just find. Only cross-domain requests did not work. I had to put everything on my server. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.