'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;

    });

});


Solution 1:[1]

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

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

Solution 2:[2]

.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
});

Solution 3:[3]

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 = [];
                }
            });
        };
      },
    ]);

Solution 4:[4]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2
Solution 3 Khairul Islam Tonmoy
Solution 4 Hamdy