Why does a cross-domain angularjs $http.post request fail when a XMLHttpRequest succeeds?

前端 未结 6 511
情歌与酒
情歌与酒 2021-02-01 10:32

I am trying to exercise the Trello API with an application key and token from an angular (version 1.0.5) webapp. The server seems correctly configured to handle CORS. A test req

6条回答
  •  南旧
    南旧 (楼主)
    2021-02-01 11:24

    Add the headers param to the $http and you'll be fine.

              var config = {
                method: 'POST',
                url: 'your url',
                headers: {
                  'Content-Type': undefined
               },
               data: {
                  "channel": "#fun-and-game",
                  "username": $scope.question.title,
                  "text": $scope.question.text,
                  "icon_emoji": ":ghost:"
              },
           };
    
          $http(config).success(function(data) {
             $scope.server_resp = data;
          }).error(function(response) {
    
          });
    

    for more info, check angularjs $http docs

提交回复
热议问题