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);
});
任何幫助,將不勝感激!