繁体   English   中英

无法使用PHP和Angular.js中的后方法获取数组数据

[英]Can not fetch array data using post methos in PHP and Angular.js

我有一个问题。 我正在使用Angular.js和PHP提交表单。 我正在使用$http服务将数据数组发送到服务器端,但是在服务器端我没有任何价值。 我在下面解释我的代码。

var supplierData=$("#billdata").serialize();
supplierData+= "&image="+newpath+"&action=add"+"&special="+$scope.example14model;
$http({
    method:'POST',
    url:"php/customerInfo.php",
    data:supplierData,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(function successCallback(response){
  console.log('respon',response.data);
},function errorCallback(response) {
})

这里的$scope.example14model接受如下数据数组。

$scope.example14model=[
         {'id':1},
         {'id':2}
]

当我在服务器端获取这些数据时,如下所示

$mulspec=$_POST['special'];

它不提供任何数据,但在打印此值时显示为[object Object],[object Object] 我需要在这里获取所有数组数据。 请帮我。

当您执行以下操作时:

"&special="+$scope.example14model

它只是在example14model属性上执行toString,默认情况下,这将为您提供所看到的内容。 我认为您需要做的就是将其转换为json。 尝试:

"&special="+JSON.stringify($scope.example14model)

这将作为json字符串在服务器端通过,因此您可能需要对对象进行一些序列化,具体取决于您要使用的对象。

评论后更新。 我自己没有在PHP中使用JSON,但为了从数据中获取对象,我认为以下方法会起作用。

$json=$_POST['special'];
$mulspec=json_decode($json);

echo(count($mulspec));

您现在应该能够计算数组中的项目

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM