简体   繁体   中英

Angularjs $http.post, passing array to PHP

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 在此输入图像描述

Thanks

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

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM