Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php&;Angularjs Ajax:从Ajax请求到php检索数据的正确方法是什么?_Php_Angularjs_Ajax - Fatal编程技术网

Php&;Angularjs Ajax:从Ajax请求到php检索数据的正确方法是什么?

Php&;Angularjs Ajax:从Ajax请求到php检索数据的正确方法是什么?,php,angularjs,ajax,Php,Angularjs,Ajax,我不想问,在编写如下代码时,如何从ajax请求中检索数据到php api: 控制器: $scope.addCustomer= function() { IndexService.addCustomer($scope.persons) .then(function(response) { console.debug('response :', response); }).cat

我不想问,在编写如下代码时,如何从ajax请求中检索数据到php api:

控制器:

        $scope.addCustomer= function() {

            IndexService.addCustomer($scope.persons)
            .then(function(response) {
                console.debug('response :', response);
            }).catch(function(error) {
                console.debug('error :', error);
            });
        }
服务:

        function addCustomer(data) {

            return $http({
                method:'POST',
                url: 'php/api/customer.php',
                data: data,
                dataType: 'json',
                contentType: 'applications/json'
            });

        }
我试着对我的php文件执行此操作,但它告诉我未定义的索引“data”

$data = $_POST['data']

问:从ajax调用到php文件检索数据的正确方法是什么?谢谢

您的服务中的
数据是什么结构?您是否尝试过
var\u dump
ing
$\u POST
查看其中是否有任何内容?是的,我尝试过var dump,但它显示数组(0)输入将不在$\u POST中;要检索它,请使用,
$data=file\u get\u contents(“php://input");
$response=json\u decode($data,true)您的服务中的
数据是什么结构?您是否尝试过
var\u dump
ing
$\u POST
查看其中是否有任何内容?是的,我尝试过var dump,但它显示数组(0)输入将不在$\u POST中;要检索它,请使用,
$data=file\u get\u contents(“php://input");
$response=json\u decode($data,true)