简体   繁体   English

如何使用angular.js发布多个请求

[英]how to post multiple requests using angular.js

I am working on a dynamic form in angular where the data can be multiple paths with other data where on save, it needs to send multiple post requests to server. 我正在以角度的动态形式工作,其中数据可以是多个路径,而其他数据在保存时需要向服务器发送多个发布请求。 Is this possible in angular? 这可能有角度吗? Here is my html , 这是我的html,

 <fieldset class="form-group pl-sm" ng-repeat="file in files">
   <div>
        <input type="text" class="form-control" autocomplete="off" name="fileLocation" ng-model="file.name">            
    </div>
        <input type="checkbox" class="switch-input" name="" ng-model="file.xxxx" />
        <input type="checkbox" class="switch-input" name="" ng-model="file.yyyy" />            
   <div class="col-sm-3">
        <select class="form-control" name="fileCenters" ng-model="file.centers" required>
            <option value="Development">Development</option>
            <option value="Sales">Sales</option>
        </select>
    </div>
</fieldset>
<a  href="" ng-click="addNew()">Add more </a>

I am not sure how i could save all the paths in a single post request. 我不确定如何在单个发布请求中保存所有路径。 So essentially it has to be a json object with multiple object entirs such as 因此,本质上,它必须是具有多个对象实体的json对象,例如

 [{
    location: 'france',
    xxxx: true,
    yyyy: false,
    center: 'sales'
   },
   {
    location: 'france',
    xxxx: true,
    yyyy: false,
    center: 'sales'
   }]

any help on angular http.post with multiple request will be great , do i need to queue up the requests with a timeout or add a callback and chain the request on success of the first request?? 对有多个请求的有角度的http.post的任何帮助都将很好,我是否需要在超时的情况下将请求排队或添加回调并在第一个请求成功时将请求链接起来?

You do not need to send data multiple times to the server. 您不需要多次将数据发送到服务器。 On submit you can send all the data at once with 提交后,您可以一次发送所有数据

$http.post(url, array).then(function(response){
    console.log(response.data);
}).error(function(){
    //If there is an error..
}).finally(function(){
    //regardless of error or not, whatever u want to do
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM