簡體   English   中英

Angularjs $ http.post,將數組傳遞給PHP

[英]Angularjs $http.post, passing array to 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這樣的東西

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM