繁体   English   中英

发布方法以使用angularjs发送数据数组

[英]Post method to send array of data using angularjs

这是我存储推入数据的数组,现在我想使用http post方法将此数据发送到服务器。

 $scope.workingSchedules = [{   
     workingDay: 'MONDAY',
     workingHours: [{ 
         fromTime: '1222' ,
         toTime: '1400'
     }]
 }];

这是我的将数据推入数组的代码。

$scope.addRow = function(){
    $scope.workingSchedules.push({
         'workingDay':'MONDAY',
         'workingHours':[{
             'fromTime':$scope.fromTime,
             'toTime':$scope.toTime
         }]
    });
    $scope.fromTime='';
    $scope.toTime='';
    $scope.workingDay='';
};

我应该如何使用正常发送此数组

 $http.post($scope.API_url,
    workingSchedules, config)
    .success(function(workingSchedules, status) {

您缺少某些部分。 Content-Type ,应与您的数据匹配。

$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=utf-8';

或者,如果您不想使用$httpProvider

$http.post($scope.API_url,workingSchedules, config, headers:{'Content-Type':"text/html"})

查看如何发送发布请求 ,以获取正确的request format

暂无
暂无

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

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