我是 AngularJS 的新手,想要进行表单 ajax 提交。我需要一些帮助或指导,了解如何传递具有相同输入名称(例如 username[])的值,以与 PHP/MYSQL 一起使用 $http.post 作为 JSON 的后端帮助。
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
</head>
<body ng-app="myApp">
<div ng-controller="tableController as tblCtrl">
<table>
<thead>
<tr>
<th>No</th>
<th>Username</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="row in rows">
<td>{{ $index + 1 }}</td>
<td><input type="text" name="{{ row.iuname }}" placeholder="{{ row.iumask }}"></input></td>
<td><input type="text" name="{{ row.iename }}" placeholder="{{ row.iemask }}"></input></td>
</tr>
</tbody>
</table>
<button ng-click="addRow()">Add Row</button>
<button ng-click="addUsers()">Save</button>
</div>
<script src="angular.min.js"></script>
<script src="app.js"></script>
</body>
</html>
JS:
var app = angular.module('myApp', []);
app.controller('tableController', ['$scope', function($scope, $http) {
$scope.rows = [{iumask:'Username',iuname:'username[]',iemask:'Email',iename:'uemail[]'}];
$scope.addRow = function() {
$scope.rows.push({iumask:'Username',iuname:'username[]',iemask:'Email',iename:'uemail[]'});
$scope.iuname = '';
$scope.iename = '';
}
$scope.iuname = "";
$scope.addUsers = function(){
}
}]);
最佳答案
这样您就可以使用 post 请求
var inputContent=[];
$scope.addValue=function(data){
inputContent.push(data);
}
$scope.submit=function(){
var promise=$http({
method : 'POST',
url : serviceUrl+"/userList",
data : $.param(inputContent), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
// set the headers so angular passing info as form data (not request payload)
});
promise.then(function(data){
alert(dat)
})
}
将您的用户列表发送到服务器中
关于javascript - AngularJS : Handling value with same input name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32546886/