0

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.

5
  • 1
    According to the angularJS api, $http.post requires some data. Try sending an empty object for testing, eg. $http.post("server.php", {}) or something like that. Commented May 23, 2014 at 18:51
  • What you're doing should work fine (see this fiddle: jsfiddle.net/ahchurch/Psq7P/1) - are you seeing any other errors? Can we see the view code that you have set up? Wondering if your controller just isn't getting called, check your routes too... Commented May 23, 2014 at 19:25
  • Is your controller defined in your html? Make sure your controller is being used. Also it looks like your code is not doing anything, the return data is not being used anywhere in your code. Commented May 23, 2014 at 19:29
  • 1
    I wonder if you're just not seeing the request in your console for some reason. Replace return data with console.log(data) in both callbacks. Commented May 23, 2014 at 19:29
  • Any errors being printed to the console? The only thing I can think of is that an error is being thrown before you controller is instantiated which causes the $http to never be called. Commented May 23, 2014 at 22:20

1 Answer 1

1

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 */);
Sign up to request clarification or add additional context in comments.

1 Comment

@MT-Developer, What doesn't work? Does the HTTP request send data to the server? Also, if you use return data, it will not update anything, since XMLHttpRequests are asynchronous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.