简体   繁体   English

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

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

This is my array where I store my pushed data, now I want to send this data to server using http post method. 这是我存储推入数据的数组,现在我想使用http post方法将此数据发送到服务器。

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

This is my code to push data into array. 这是我的将数据推入数组的代码。

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

How am I suppose to send this array using normal 我应该如何使用正常发送此数组

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

You are missing some parts. 您缺少某些部分。 Content-Type , should be matched to your data. Content-Type ,应与您的数据匹配。

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

Or if you don't want to use $httpProvider : 或者,如果您不想使用$httpProvider

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

Look at How to send post request , for the right format of the request . 查看如何发送发布请求 ,以获取正确的request format

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

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