2017-04-05 3 views
0

ヘッダーと要求本文の両方で投稿要求を送信しようとしています。これまでのところ、私はこの点に達しています:ngResource:Angularjs - ヘッダーと要求本文を含む投稿要求を送信します。

この場合、ペイロードの配置場所はわかりません。また、電話をかけているときに、私は現在次のようなことをしようとしています:

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); 
        }); 

助けていただければ幸いです!

答えて

0

私が興味を持っている人のためのソリューションに来た:

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); // this will go in the 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 the page so newly created job can be seen 
       window.location.reload(); 
      }). 
      catch(function (error) { 
       console.log('Create job error is'); 
       console.log(error); 
      }); 
関連する問題