Angularjs $http.post,将数组传递给PHP

前端之家收集整理的这篇文章主要介绍了Angularjs $http.post,将数组传递给PHP前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用服务来更新数据库表.

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);
}

数组返回空.我错误地传递了数组吗?

Chrome Dev

谢谢

解决方法

我使用PHP已经有一段时间了,但$_POST不包含请求参数吗? $http.post通过JSON有效负载发送数据,而不是请求参数.所以,你需要使用像 json_decode这样的东西

猜你在找的Angularjs相关文章