gpt4 book ai didi

angularjs - 如何将动态输入数据添加到angularjs中的$http数据

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:24:29 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com