Php&;Angularjs Ajax:从Ajax请求到php检索数据的正确方法是什么?
我不想问,在编写如下代码时,如何从ajax请求中检索数据到php api: 控制器: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
$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)代码>