user6747379
user6747379

Reputation:

Why not working angular js ajax when $http.get use in this code?

var app = angular.module("mymodule",[]);

app.controller("employeeController",function($scope,$http){
    var url ="data/records.json";

    $http.get(url).success(function(response){
        $scope.employees =response;

    });

});

Upvotes: 2

Views: 116

Answers (4)

Khairul Islam Tonmoy
Khairul Islam Tonmoy

Reputation: 314

Try this way

app.controller("paymentRequestController", ["$scope", "$http", function ($scope, $http) {
        
        $scope.payment_method_info = [];
        $scope.rate = 0;
        $scope.getPaymentInfo = function () {
            $http({
                method: "POST",
                url: url,
            }).success(function (response) {
                if (response.length > 0) {
                    $scope.rate = response[0].rate;
                    $scope.payment_method_info = response;
                } else {
                    $scope.rate = 0;
                    $scope.payment_method_info = [];
                }
            });
        };
      },
    ]);

Upvotes: 0

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41397

.success is deprecated since angular version 1.4 To catch the promise you can use then.

Note that response of the then return data inside the data property. so you need to access the data property of that response.

$http.get(url).then(function(response){
        $scope.employees =response.data
});

Upvotes: 1

Hamdy
Hamdy

Reputation: 440

i don't have enought reputation. i want to add on @Jayanta reply this is another syntax:

.success(function (data, status, headers, config) {
          deffered.resolve(data);

so when you try to add "data" to console.log(data) it will dislay the right data.

Upvotes: -1

Sajeetharan
Sajeetharan

Reputation: 222582

You should access response.data,also replace success with then,.success has been deprecated.

$http.get(url).then(function(response){
        $scope.employees =response.data;
});

Upvotes: 3

Related Questions