我使用的是服务,更新数据库表。
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浏览器开发
Chrome Dev
感谢
这是一段时间,因为我用PHP,但并不 $ _ POST
只包含要求PARAMATERS? $ http.post
通过JSON有效载荷发送数据,而不是请求参数。所以,你需要使用像 json_de code
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