Mostafa Talebi
Mostafa Talebi

Reputation: 9173

Angular $http request in the controller does not work

I have the following controller. It works all fine (it parses the data and sends them into the view). The only problem I have is that it does not send $http request. Here is the code block of controller (i just send a test $http without any value from the view just to test it works or not, which does not work): (It's also worth mentioning that I check via browser's console to see if any ajax request is sent or not)

// Controller
LoginApp.controller("RegisterController", function($scope, $http, registerService){

        var username  = null;
        var password = null;

        $scope.registerSubmit  = function(){
            username = $scope.register.username;
            password = $scope.register.password;


        };


        //registerService.CheckUser();
        $http.post('server.php', {name : 'something'})

            .success(function(data, status, header, config){

                return data;

            })

            .error(function(data, status, header, config){

                return data;

            }); // end of $http request
    });

EDIT: I have edited what @JoshBeam has recommended, passing data to the post(), but it does not change anything.

Upvotes: 0

Views: 104

Answers (1)

Josh Beam
Josh Beam

Reputation: 19772

You need to pass data along with the HTTP request. According to the AngularJS documentation, it is in this format: post(url, data, [config]);

Thus:

$http.post('server.php', /* your data */);

Upvotes: 1

Related Questions