0
我正在尝试发送带有标题和请求正文的请求。到目前为止,我已经达到了这一点:ngResource:Angularjs - 发送带有标题和请求正文的请求
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; // this will go in the body request
}
}
});
}
我不知道在哪里放置有效载荷在这种情况下,任何帮助吗?还打电话时,我目前正在尝试做类似的事情:
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);
});
任何帮助,将不胜感激!