1

This my response from JSP, I am trying to get data from the response.

$http.get('url.jsp', data).then(successCallback, errorCallback);

I am facing "data is not defined"

enter image description here

How can I retrieve the data only?

0

2 Answers 2

5

You're confusing the request data field with response data. According to the AngularJS $http API:

and request data must be passed in for POST/PUT requests [concerning] $http.post('/someUrl', data, config).then(successCallback, errorCallback);

Instead of using the request data field you listed, you should add a parameter to your successCallback for the response data.

Here's some example code I've written:

$http.get('/categories/graph')
      .then(function successCallback(res) {
         $scope.scopeGraph = res.data;
      }, function errorCallback(err) {
         console.log("Error: " + angular.toJson(err));
      });

Notice how I read the data from the res variable in the successCallback, and don't have to include request data for a get.

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

2 Comments

Thanks sir. I am confusing the request data field with response data. According to the AngularJS $http API:
I'm glad I can help. Two fields with the same name and general purpose can be confusing.
0

Try with below code syntax for $http.get, it should be working fine:

$http.get('url.jsp').then(
  // successCallback
  function(successResponse) {
    // here you can access data got in response as:
    var data = successResponse.data;        
    console.log(data);
  },
  // error callback
  function(errorResponse) {
    console.log(errorResponse);
  });

For more details, read AngularJs Doc:

Other helpful link: https://www.w3schools.com/angular/angular_http.asp

Comments

Your Answer

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