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 ?
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 ).
eg JSON.stringify({ data: $scope.keywords, otherStuff: otherStuff })
that s it i suppose.
So you would post :
$http.post('server.php', { "data" : $scope.keywords,"anotherData":anotherData})
And receive data:
$_POST['data'] and $_POST['anotherData']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.