ngResource: Angularjs - Send post request with headers and request body -


i trying send post request both header , request body. far have reached point:

createjob: function(jobname, jobaddress, jobcontact, jobcomments) {                     var payload = {                         name: jobname,                         address: jobaddress,                         contact: jobcontact,                         comments: jobcomments                     };                     console.log(payload);                     return $resource(route, {}, {                        save: {                            method: 'post',                            header: {'content-type': 'application/json'},                            transformrequest: function(data){                                console.log('data in transform request is');                                console.log(data);                                return data; // go in body request                            }                        }                     });                 } 

i not sure place payload in case, help? when making call, trying like:

createjob(this.jobname, this.jobaddress, this.jobcontact, this.jobcomments).                     save().$promise.                     then(function (response) {                         console.log('create job response is');                         console.log(response);                     }).                     catch(function (error) {                         console.log('create job error is');                         console.log(error);                     }); 

any appreciated!

i came solution interested:

createjob: function(jobname, jobaddress, jobcontact, jobcomments) {             var payload = {                 name: jobname,                 address: jobaddress,                 contact: jobcontact,                 comments: jobcomments             };             console.log(payload);             return $resource(route, {}, {                 save: {                     method: 'post',                     transformrequest: function(data){                         console.log('data in transform request is');                         console.log(data);                         return angular.tojson(data); // go in body request                     }                 }             }).save({}, payload);         }  createjob(this.jobname, this.jobaddress, this.jobcontact, this.jobcomments).$promise.             then(function (response) {                 console.log('create job response is');                 console.log(response);                 //refresh page newly created job can seen                 window.location.reload();             }).             catch(function (error) {                 console.log('create job error is');                 console.log(error);             }); 

Comments