最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Issue with HTTP Request with Patch method in Angular JS - Stack Overflow

programmeradmin1浏览0评论

Following is my code:

  $http({
      url: '/' + wishlist_id,
      method: 'PATCH',
      params: {
          list: {
              add_pany_ids: ['61737'],
              name: 'My Wishlist'
          },
          api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
      }
  })
      .success(function(response) {
          console.log(response);
      }).
  error(function(response) {
      console.log(response);
      return false;
  });

I am getting bad request error but same request with patch method is working in REST CLIENT on chrome.

Following is my code:

  $http({
      url: 'https://apistage.dealsignal./api/v0/pany_watchlists/' + wishlist_id,
      method: 'PATCH',
      params: {
          list: {
              add_pany_ids: ['61737'],
              name: 'My Wishlist'
          },
          api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
      }
  })
      .success(function(response) {
          console.log(response);
      }).
  error(function(response) {
      console.log(response);
      return false;
  });

I am getting bad request error but same request with patch method is working in REST CLIENT on chrome.

Share Improve this question edited Sep 15, 2015 at 10:46 Manish Kr. Shukla 4,4771 gold badge21 silver badges35 bronze badges asked Sep 15, 2015 at 10:44 Seema SharmaSeema Sharma 893 bronze badges 1
  • 2 Most of the time when a request fails from the browser, but succeeds in a Postman or another REST client, it means that CORS in the server is not set correctly. – Ori Drori Commented Sep 22, 2015 at 11:21
Add a ment  | 

2 Answers 2

Reset to default 7 +25

Please see the Angular Doc. This will be Data not params.

$http({
  url: 'https://apistage.dealsignal./api/v0/pany_watchlists/' + wishlist_id,
  method: 'PATCH',
  data: {
      list: {
          add_pany_ids: ['61737'],
          name: 'My Wishlist'
      },
      api_key: 'CtxY3Kpc7ZDL8VDfLmPt9wss'
  }
}).success(function(response) {
      console.log(response);
  }).
  error(function(response) {
  console.log(response);
  return false;
});

I am not sure about it, but may be the problem is that the parameter "params" should be named "data", as when you make a POST request.

Hope it helps.

发布评论

评论列表(0)

  1. 暂无评论