【问题标题】:Post method to send array of data using angularjs使用 angularjs 发送数据数组的 Post 方法
【发布时间】:2016-10-24 07:34:26
【问题描述】:

这是我存储推送数据的数组, 现在我想使用 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) {

【问题讨论】:

标签: javascript html arrays angularjs


【解决方案1】:

您缺少一些部分。 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"})

查看How to send post request,寻找request 的右侧format

【讨论】:

  • 您好,感谢您的回答!!我已经正确应用了 conf 并且我的帖子,get ,put 正常工作。我在将数据发送到 UI 中的数组然后将该数据发送回服务器时遇到问题。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 2012-09-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多