5

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

5
  • What's the console say about the request? Commented Jul 31, 2013 at 15:56
  • successful, request. Returns the DB action, just the array not being sent over in POST Commented Jul 31, 2013 at 16:00
  • Interesting... what is your PHP sending back? Commented Jul 31, 2013 at 16:02
  • Right now I am just trying to get PHP to print $_POST. It's returning Array ().... Commented Jul 31, 2013 at 16:05
  • How about $_POST['newGalleryArray'] Commented Jul 31, 2013 at 16:06

1 Answer 1

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

DOH!! Just had to add $json = json_decode(file_get_contents("php://input"));
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.