0

As title, I want to catch Http response that sent by the browser.
Let say a redirect to "http://domain/api/something", actually, a GET request to "http://domain/api/something" which return a JSON data.
How can I get that data on first load using AngularJs?

2
  • Please be more descriptive about what you're trying to accomplish, and also make some attempt at doing so. Commented Jul 22, 2016 at 4:28
  • Assume that user enter my page "domain/api/something" on browser then my server returns a JSON data/ a Html page or so. In case of a Html page, the browser will render it. The question is, how can I also get that Html page in text/HTML format without sending another request. Commented Jul 22, 2016 at 4:59

2 Answers 2

1

You should modify your code as below

app.service('feedbackService', function ($http) {
   this.getFeedbackPaged = function () {
      return $http.get('http://domain/api/something');
   };
});

app.controller('feedbackController', function ($scope, feedbackService, $filter) {
  // Constructor for this controller
  init();

  function init() {
      feedbackService.getFeedbackPaged().then(function(data){
          $scope.feedbackItems=data;
      });
  }
});
Sign up to request clarification or add additional context in comments.

2 Comments

By this way, I'll send another request rather than catch a response that already sent by Browser, isn't it?
Please give more descriptive. once you load the init(); It will call the http GET method and response will store in $scope.feedbackItems. Thanks
0

Use $http service as follows.

$http.get(
  'http://domain/api/something'
).then(function successCallback(response) {
  $scope.data = JSON.parse(response.data);
}, function errorCallback(response) {
  // error handler
});

reference: https://docs.angularjs.org/api/ng/service/$http

Comments

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.