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

时间:2015-05-12 05:04:43

标签: javascript angularjs rest http-post

我正在处理一个动态表单,其中数据可以是多个路径,其他数据在保存时,需要向服务器发送多个发布请求。这有可能是有角度的吗? 这是我的HTML,

def reverseInteger(x):
    x_string = str(x)                           
    x_list = list(x_string)                     
    x_reversedlist = reversed(x_list)          
    x_reversedstring = "".join(x_reversedlist)  
    x_reversed = int(x_reversedstring)          
    return x_reversed

def paliproduct(i1, i2):
    while i1 < 1000 and i2 < 1000:
            product = i1 * i2
            i1 += 1
            i2 += 1
            if product == reverseInteger(product):
                return product

print(paliproduct(100, 100))

我不确定如何在单个帖子请求中保存所有路径。所以基本上它必须是一个具有多个对象entirs的json对象,例如

 <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>

对具有多个请求的角度http.post的任何帮助都会很棒,我是否需要使用超时排队请求或添加回调并在第一次请求成功时链接请求?

1 个答案:

答案 0 :(得分:1)

您无需多次向服务器发送数据。提交后,您可以使用

一次性发送所有数据
$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
})