Join the Stack Overflow Community
Stack Overflow is a community of 6.6 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am using a service to update a DB table.

myApp.factory('createGal', function ($http, $q)
{
    return {
        createGal: function ()
        {
            var deferred = $q.defer();
            var newGalleryArray = {};

            newGalleryArray.galleryName = 'New Image Gallery';
            newGalleryArray.client      = 245;

            $http.post('/beta/images/create', {newGalleryArray: newGalleryArray}).success(function(data)
            {
                console.log(data);
                deferred.resolve(data);
            });

            return deferred.promise;
        }
    };
});

PHP

public function create()
{
    print_r($_POST);
}

The array is returning empty. Am i passing the array incorrectly?

Chrome Dev enter image description here

Thanks

share|improve this question
    
What's the console say about the request? – tymeJV Jul 31 '13 at 15:56
    
successful, request. Returns the DB action, just the array not being sent over in POST – Bungdaddy Jul 31 '13 at 16:00
    
Interesting... what is your PHP sending back? – tymeJV Jul 31 '13 at 16:02
    
Right now I am just trying to get PHP to print $_POST. It's returning Array ().... – Bungdaddy Jul 31 '13 at 16:05
    
How about $_POST['newGalleryArray'] – tymeJV Jul 31 '13 at 16:06
up vote 6 down vote accepted

It's been a while since I've used PHP, but doesn't $_POST just contain request paramaters? $http.post sends data through a JSON payload, not request parameters. So, you'll need to use something like json_decode

share|improve this answer
    
DOH!! Just had to add $json = json_decode(file_get_contents("php://input")); – Bungdaddy Jul 31 '13 at 16:18
    
If you have jQuery on the side send your post data through $.params and add Content-Type 'application/x-www-form-urlencoded' to the request header. This way you can just use the $_POST global. – Oliver Jul 31 '13 at 16:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.