this is my 1st time with AngulerJS. I'm trying to POST data to the server.
AngularJS Code
var app = angular.module("myApp", []);
var BASE_URL = "http://localhost/project/api/Data/";
var GET_DATA = BASE_URL+"get_data";
console.log(GET_DATA);
app.controller('myCtrl', function($scope, $http) {
var inputs = { "user_id": "3"};
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post(GET_DATA , inputs, config)
.success(function (response, status, headers, config) {
$scope.content = response.error;
$scope.statuscode = response.status;
$scope.statustext = response.statusInfo;
console.log(response);
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
});
This code is posting data to the server, but with something wired format. Below is my print_r($_POST); result :
Array
(
[{"user_id":"3"}] =>
[0] =>
)
this is wrong result, I am expecting something like
Array
(
user_id => 3
)
Note : I'm using CodeIgniter framework at server side.
var inputs = "user_id=3";&.