1. 程式人生 > >關於AngularJs中$http post、get 傳送和接受引數詳解

關於AngularJs中$http post、get 傳送和接受引數詳解

1、POST、GET攜帶引數的寫法不一樣,如下:

?
1 2 3 4 5 6 7 $http({method: 'post', url: './feedback/mail', data:{content:content,mailOrqq:mailOrqq,type:'chat-page-feedback'} }).success(function(data, status, headers, config) { console.log("IT部落是個神奇的網站"); }).error(function(data, status, headers, config){
console.error('我錯了'); });
?
1 2 3 4 $http({method: 'GET',url:'./topic/getTopicCommentList', params:{topicId:$stateParams.topicId} }).success(function(data, status, headers, config) {}) .error(function(data, status, headers, config){});
聰明的你一定看出來了,POST最好用Data攜帶資料、GET最好用params攜帶資料,兩者使得區別如下描述: 

  • params – {Object.<string|Object>} – Map of strings or objects which will be serialized with theparamSerializer and appended as GET parameters.
  • data – {string|Object} – Data to be sent as the request message data.
詳情