0

I developed one RESTful web service. The link return json code, like these:

{"status":"itPassed","dest":"/elk2/kr659p/home"}

Now I want to display these data in my screen.

View:

<!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="../controllers/webservice.js"></script>
</head>

<body>
<div ng-controller="Hello">
    <p>The ID is {{greeting.status}}</p>
    <p>The content is {{greeting.dest}}</p>
</div>
</body>
</html>

My Controller

angular.module('myApp', []).controller('Hello', function ($scope, $http) {
alert(1);
$http.get('http://9.124.130.197:2020/PatchAdminTool/rest/service/getstatus/123').
    success(function(data) {
        alert(2);

        $scope.greeting = data;
        alert(data);

    });
});
halfer
  • 19,824
  • 17
  • 99
  • 186
swetha m
  • 51
  • 1
  • 1
  • 7
  • Is that all your codes? What is inside webservice.js? You should start with basic angular js tutorial first before you jump to REST api calls. – Andy Nov 19 '14 at 06:21
  • These is my webservice.js – swetha m Nov 19 '14 at 06:25
  • function Hello($scope,$http) { $http.get('http://localhost:2020/PatchAdminTool/rest/service/getstatus/123'). success(function(data) { alert(data); $scope.greeting = data; alert(data); }); } – swetha m Nov 19 '14 at 06:25
  • I see, in that case, that's not the right way to define a controller, see @sagie gur-ari 's answer. – Andy Nov 19 '14 at 06:29

2 Answers2

0

no errors in console? because that's not really how you write a controller in angularJS. you should have something like

angular.module('mymodule', []).controller('Hello', function ($scope, $http) {
    $http.get('http://9.124.130.197:2020/PatchAdminTool/rest/service/getstatus/123').
        success(function(data) {
            alert(data);
            $scope.greeting = data;
            alert(data);

        });
});

by the way, does the alert actually show something?

sagie
  • 1,744
  • 14
  • 15
  • I define this is way.But i am not getting data. – swetha m Nov 19 '14 at 06:47
  • you mean, the success function in the http.get is never called? or is called and data is empty? and... what happens if you paste that url in the browser, what do you see? can you also define the error function for the $http.get as written in https://docs.angularjs.org/api/ng/service/$http to see if there is some error? by the way – sagie Nov 19 '14 at 06:51
  • I copy pasted that url in broser.it will display json object. – swetha m Nov 19 '14 at 06:57
  • I pasted url in browser.it display json object.{"status":"itPassed","dest":"/elk2/kr659p/home"} – swetha m Nov 19 '14 at 06:58
  • but did the get.sucess call get fired in your app? did you see any alert? did you put the error function as well to the get call? – sagie Nov 19 '14 at 07:05
  • also in chrome check in network tab to see that both webservice.js and that the url of the get call are being sent and that they don't return errors. – sagie Nov 19 '14 at 07:06
0

Did you try to place breakpoints?
Open the Chrome Debugger - Place the following breakpoints:

  1. on the $http.get line - see if you are reaching it.
  2. on the alert(data) line - see if the data contain what you expected.
chenop
  • 4,743
  • 4
  • 41
  • 65
  • I tried to place alert before $http.get its working and i plased one more alert after $http.get its not display. – swetha m Nov 19 '14 at 06:28
  • So you do not reach the $http call. Probably something is wrong in the way you write the Controller. See @sagie gur-ari answer. – chenop Nov 19 '14 at 06:56