1

I try to post data from angularJS to my web-Service and want to get data back.

The post-request works great, I get data back (which I hardcoded in PHP), but (after 2h searching) my problem is that I cant send some Post-Data.

Here my code:

   angular.module('LunchApp', [])
  .controller('MessagesCtrl', function($scope, $http){
        $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
        var postData = { callMethod: 'getChat' };
        $http.post(url, postData).success(function(data){
            $scope.messages = data;
        });
  });

I have tried many solutions:

but nothing works for me... :(

If I try it with a RESTful TestClient, it works perfectly. all posted data reach the server. But not with AngularJS :(

3
  • Did you take a look at this question? stackoverflow.com/questions/11442632/… Commented Jan 13, 2015 at 20:11
  • Is your variable "postData" in the format expected by $http.post function? Commented Jan 13, 2015 at 20:16
  • oh my god... $.param(); is the solution. thank you so much! Commented Jan 13, 2015 at 20:23

0

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.