0

I'm completely new to webdev and i need to use AngularJS. I really have troubles with using $http.post.

app.controller('searchCtrl', function($scope, $http, $log) {
    $scope.search = function() {
        $http.post('server.php', { "data" : $scope.keywords})
        .success(function(data, status) {
            $scope.result = data;
        })
    };

I use this controller (and it works fine), but i would like to pass a second parameter (a string) to server.php, in addition to $scope.keywords.

How do i do that, both on server and client side ?

Saksham
  • 9,037
  • 7
  • 45
  • 73

2 Answers2

0

post call expects path which is server.php and body a JSON object

what you can simply do is use JSON.stringify(any json abject).

e.g. JSON.stringify({ data: $scope.keywords, otherStuff: otherStuff })

that s it i suppose.

Ankur Soni
  • 746
  • 6
  • 17
0

So you would post :

$http.post('server.php', { "data" : $scope.keywords,"anotherData":anotherData})

And receive data:

$_POST['data'] and $_POST['anotherData']