0

I am using AngularJS to send a $http.post request this is my AngularJS code:

var app = angular.module('myApp', [],function($httpProvider)
{
    $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

});
app.controller('notificationsCtrl', function($scope, $http) {
    $http.get("listAllNotifications.php")
        .then(function (response) {$scope.notifications = response.data.records;});
    $scope.removeRow = function (row)
    {
        var parameter = JSON.stringify({'actions': row});
        $res = $http.post("../api/notifications.php",parameter)
            .then(function (response) {$scope.notifications = response.data.records;});
    }
});

this is the PHP server side codes that receives it :

<?php
print_r($_POST,TRUE);

and this is the print result:

{"actions":1450591689}=""

What am I doing wrong in order to get it as key=>value in the $_POST

thanks

A J
  • 3,970
  • 14
  • 38
  • 53
Amit
  • 1
  • 1
  • 1
    use `jQuery.param` instead of `JSON.stringify`. – jcubic Jan 04 '16 at 08:57
  • Possible duplicate of [How can I post data as form data instead of a request payload?](http://stackoverflow.com/questions/11442632/how-can-i-post-data-as-form-data-instead-of-a-request-payload) – Clay Jan 04 '16 at 08:59
  • 2
    Do not use `JSON.stringify` – Eria Jan 04 '16 at 09:04
  • what exactly you are trying to do? You can send JSON object directly from server using echo json_encode($_POST); – Yogesh Jan 04 '16 at 10:23

0 Answers0