Angularjs $ http.post,传递数组PHP [英] Angularjs $http.post, passing array to PHP
本文介绍了Angularjs $ http.post,传递数组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浏览器开发
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
这篇关于Angularjs $ http.post,传递数组PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文