Model array values are not being submitted by $http service

34 Views Asked by At

I defined an array in controller to create a array model. i.e. $scope.campaignPublish[] and I am using in my view template like

<textarea rows="" cols="" name="description" ng-model="campaignPublish['description']"> </textarea>

<input type="text" name="title" ng-model="campaignPublish['title']">

When I submit the form I'm getting all of the form values in this array i.e. $scope.campaignPublish[] but when I'm using $http.post, the data is not being submitted to server. My ajax call is

console.log($scope.campaignPublish); // Getting all form data here 

$http.post('url', {'id': campaignId, 'data': $scope.campaignPublish}).then(function (response) {
   //$http.post is not submitting the form data on server
});

I read some articles and got to know that it is happening because of http headers. I've already tried each and every solution posted on SO but no one exactly worked. Can anybody tell me where I am doing wrong ?

1

There are 1 best solutions below

1
On
$http({
        method: 'POST',
        url: url,
        headers: {
            'Content-Type': 'text/plain'
        },
        data: $scope.campaignPublish
    }).success(function (reply) {
        console.log('sucess');
    }).error(function (reply) {
        console.log('error');
    });