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"
How can I retrieve the data only?
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.
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