下面是控制器:
app.controller(“ DemoController”,函数($ scope,$ http){
$scope.Save = function () {
var Details = [];
Details = $scope.UserForm.AllFields;
$http.post(
"api/Add.php",
{'DemoDetails':$scope.Details}
).then(function successCallback(response) {
// Store response data
alert(response.data);
}, function errorCallback(response) {
alert(response.data);
});
};
});
下面是HTML表单:
`<form method="POST">
<input type="text" placeholder="Email" name="username" required="">
<input type="text" placeholder="Password" name="password" required="">
<input type="submit" name="login" ng-click="Save()" value="login"></label>
</div>
</form>`;
下面是php脚本:
`<?php
$postdata = file_get_contents("php://input");
if(isset($postdata) && !empty($postdata)){
$request = json_decode($postdata);
$username = $request->username;
$password = $request->password;
}`;
并保存到datatabse
答案 0 :(得分:0)
您必须像这样序列化表格:
var serializedData = UserForm.serialize();
scope.onSubmit({data: serializedData});
在进一步介绍之前,请先看一下该指令,这是一种使用指令来完成您要尝试执行的操作的绝妙方法。 Retrieve all inputs values from a form AngularJS