在php中解析angularjs数组
我是Anggularjs新手。我有一个表单并将ng模型数组发送到php文件,我得到了错误未定义的索引,不知道如何在php中解析angularjs发送的数组 html表单的一部分在php中解析angularjs数组,php,angularjs,forms,Php,Angularjs,Forms,我是Anggularjs新手。我有一个表单并将ng模型数组发送到php文件,我得到了错误未定义的索引,不知道如何在php中解析angularjs发送的数组 html表单的一部分 <div class="form-group" > <label>Street<span class="error">*</span></label><span ng-s
<div class="form-group" >
<label>Street<span class="error">*</span></label><span ng-show="!userForm.street.$pristine && userForm.street.$invalid || (userForm.street.$touched && !userForm.street)" class="error">Must be a number</span>
<input type="text" id="strret" class="form-control" name="userForm.street" ng-model="userForm.street" required ng-value="userForm.street" />
</div>
<div class="form-group" >
<label>Tel<span class="error">*</span></label><span ng-show="!userForm.tel.$pristine && userForm.tel.$invalid || (userForm.tel.$touched && !userForm.tel)" class="error">Must be number</span>
<input type="text" class="form-control" name="userForm.tel" ng-model="userForm.tel" required ng-pattern="/^[0]{1,13}$/" ng-value="userForm.tel"/>
</div>
我的问题是如何在PHP$_POST[]中获取userForm.street和userForm.tel……在stackoverflow上也有类似的问题,但在PHP文件中没有任何这样做的示例。为了以表单编码格式发送数据,您需要将其序列化 内部默认值是将其序列化为JSON 使用服务 不要忘记在将要使用它的地方注入服务或控制器 否则,如果使用作为
application/json
发送数据的$http
默认值,则需要使用file\u get\u contents('php://input“)
因为“$\u POST将为空
$data = json_decode(file_get_contents('php://input'));
你可能想看看这个问题,因为我认为它解决了与你类似的问题:我和你处于相同的情况,我最终使用了JSON,因为使用angular更简单。上面的问题甚至有一个关于如何在PHP端检索JSON的好例子。谢谢你的回答,我正在阅读这篇文章,如果我找到解决方案,我会发布它。仍然没有运气,获取错误未定义的索引街道…我知道如何发送数据,但如果我想获取已发送数组的值,我不知道我的php应该是什么样子…我已经尝试了上面的所有方法,需要显示php代码并确定您使用的上述解决方案中的哪一个。错误:$httpParamSerializerJQLike未定义获取此错误。因为您没有将其作为依赖项注入到您正在使用的组件中。请参阅上面代码下的注释这里是我的控制器angular.module(“app”,[]).controller(“ctrl”、[“$scope”、“$http”、函数($scope、$http、$httpParamSerializerJQLike){});我不知道如何设置$httpParamSerializerJQLike…它显示了这个错误:$httpParamSerializerJQLike不是一个函数
$http({
method :'POST',
url:'post.php',
data: $httpParamSerializerJQLike($scope.userForm),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success...
$data = json_decode(file_get_contents('php://input'));