0

This is my array where I store my pushed data, now I want to send this data to server using http post method.

 $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) {
3
  • Your data is supposed to be an object, so make it like this $http.post($scope.API_url, {data: workingSchedules}, config), Please check if the question already exists before posting, see comment below. Commented Jun 22, 2016 at 11:39
  • Possible duplicate of stackoverflow.com/questions/28851154/… Commented Jun 22, 2016 at 11:40
  • Refer : stackoverflow.com/a/37965742/6449750 this too Commented Jun 22, 2016 at 12:06

1 Answer 1

0

You are missing some parts. Content-Type, should be matched to your data.

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

Or if you don't want to use $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.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey, thanks for answering!! I have applied conf properly & my post, get ,put works properly. I am having problem in sending the data i pushed into an array in UI and then sending that data back to server. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.