Javascript 将数据从Angular表单传递到PHP
我试图通过ajax将表单数据保存在Angular中以存储.php文件。但是,数据似乎不是通过文件正确获取的。有人能指出错误吗Javascript 将数据从Angular表单传递到PHP,javascript,php,angularjs,Javascript,Php,Angularjs,我试图通过ajax将表单数据保存在Angular中以存储.php文件。但是,数据似乎不是通过文件正确获取的。有人能指出错误吗 <form id="form1" post="content/store.php"> <div class="form-group"> <label for="examplename">Name</label> <input type="text" class="form-co
<form id="form1" post="content/store.php">
<div class="form-group">
<label for="examplename">Name</label>
<input type="text" class="form-control" id="examplename" placeholder="Enter your name">
</div>
<div class="form-group">
<label for="exampleemail">Email</label>
<input type="email" class="form-control" id="exampleemail" placeholder="Enter your email">
</div>
<button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>
</form>
STORE.PHP
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
@$email = $request->email;
@$pass = $request->pass;
echo $email;
?>
如果要在控制器中使用 电子邮件:$scope.email 及 名称:$scope.name 或者密码,您需要在视图中具有ng模型绑定,如下所示:
<form id="form1" post="content/store.php">
<div class="form-group">
<label for="examplename">Name</label>
<input type="text" class="form-control" id="examplename" placeholder="Enter your name" ng-model="name">
</div>
<div class="form-group">
<label for="exampleemail">Email</label>
<input type="email" class="form-control" id="exampleemail" placeholder="Enter your email" ng-model="email">
</div>
<button type="submit" class="btn btn-default" ng-click="submitting()" >Submit</button>
</form>
名称
电子邮件
提交
您应该声明您的输入ng型号
i、 e
<input type="email" ng-model="email" class="form-control" id="examplename" placeholder="Enter your name">
<input type="password" ng-model="pass" class="form-control" id="exampleemail" placeholder="Enter your email">
注意:
如果希望将输入字段作为密码,请更改type=“password”
或
如果您希望将输入保持在控制器中,只需更改即可
$scope.email
和$scope.name
但最好在输入中声明这些字段,即ng model=“email”
和ng model=“pass”
尝试$\u POST而不是file\u get\u内容(“php://input");
<input type="email" ng-model="email" class="form-control" id="examplename" placeholder="Enter your name">
<input type="password" ng-model="pass" class="form-control" id="exampleemail" placeholder="Enter your email">
email: $scope.email,
pass: $scope.password