2013-07-31 44 views
5

我正在使用服务来更新数据库表。

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浏览器开发 enter image description here

感谢

+0

控制台对请求的说明是什么? – tymeJV

+0

成功,请求。返回数据库操作,只是不在POST中发送的数组 – Bungdaddy

+0

有趣...您的PHP发送回来了什么? – tymeJV

回答

6

这已经有一段时间,因为我用PHP,但不$_POST只包含请求PARAMATERS? $http.post通过JSON有效负载发送数据,而不是请求参数。因此,您需要使用类似于json_decode

+0

DOH!只需要添加$ json = json_decode(file_get_contents(“php:// input”)); – Bungdaddy

+0

如果你有jQuery的一方通过$ .params发送你的发布数据,并添加内容类型'application/x-www-form-urlencoded'到请求头。这样你可以使用$ _POST全局。 – Oliver