Showing posts with label ajax get method. Show all posts
Showing posts with label ajax get method. Show all posts

Friday, November 4, 2016

Angularjs ajax get or post method example from controller


app.controller('TestController', function($scope, $http) {
    $scope.name = "Pritom Kumar";
    $scope.posts = ["a", "b"];
    
    $http.post('lists_json', {id: 1, name: $scope.name}).
    success(function(response, status, headers, config) {
        console.log("Success=" + response);
    }).
    error(function(response, status, headers, config) {
        console.log("Error=" + response);
    });
    
    $http.get('lists_json?id=1&name='+$scope.name+"&list="+$scope.posts).
    success(function(response, status, headers, config) {
        console.log("Success=" + response);
    }).
    error(function(response, status, headers, config) {
        console.log("Error=" + response);
    });
});