作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
I have a form which has input boxes generated dynamically, now how can I add the dynamic form data to the data of $http in angularjs?
Controller 代码:
app.controller('saveQues', function ($scope, $http, $location){
$scope.insertData=function(){
$http({
url: "savequestions.php",
method: "POST",
data: #how to add here,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response){
console.log('then');
}).catch(function(response) {
console.error('Gists error', response.status, response.data);
})
.finally(function() {
console.log("finally finished gists");
});
}
});
最佳答案
在 View 中使用 ng-model 将该输入绑定(bind)到 Controller 中的数据,然后在单击按钮时调用 http post。
在 View 中:
<input type="text" ng-model="toBind"></div>
在模型中:
$scope.insertData=function(){
$http({
url: "savequestions.php",
method: "POST",
data: $scope.toBind,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}).then(function(response){
console.log('then');
}).catch(function(response) {
console.error('Gists error', response.status, response.data);
})
.finally(function() {
console.log("finally finished gists");
});
关于angularjs - 如何将动态输入数据添加到angularjs中的$http数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45925914/
我是一名优秀的程序员,十分优秀!