Ionic v1 AngularJS $ http POST请求无效

时间:2017-05-16 11:58:27

标签: javascript angularjs ionic-framework angularjs-service angularjs-http

我尝试向其他API发送POST请求,但我似乎无法正确执行,我不知道它是否是语法,或者它可能是什么,我尝试了许多不同的方法,但似乎没有任何工作。这里是POSTMAN正在使用的服务的一些图片(这里一切正常)。

  1. 标题 enter image description here

  2. 回复enter image description here

  3. 的正文

    但是当我尝试通过AngularJS使用服务时,它不断向我发送错误消息,本地主机服务器甚至检测到有请求,因为我可以在Eclipse的控制台上看到它,但它没有& #39; t使用togglebreakpoints运行调试器,并使用POSTMAN。

    这是发送$ http请求的众多尝试之一

        var json = { practiceId: 1 };
    
        $http({
            method: "POST",
            url: "https://localhost/GetAppointmentTypes",
            data: JSON.stringify(json),
            headers: {
              "Content-Type": "application/json",
              "AERONA-AUTH-TOKEN": $window.localStorage['token']
            }
        })
        .success(function(data) {
          $ionicPopup.alert({
                title: 'WORKING'
          });
        })
        .error(function (errResponse, status) {
          if(status == 403){
                $ionicPopup.alert({
                    title: '403'
            });
          }
        });
    

    但是enter image description here

    这是另一次尝试

      var url = 'https://localhost/GetAppointmentTypes';
    
      var parameter = JSON.stringify({practiceId:1});
    
      var headers = {
        "Content-Type": "application/json",
        "AERONA-AUTH-TOKEN": $window.localStorage['token']
      };
    
    
      $http.post(url, parameter, headers).then(function(response){
          $ionicPopup.alert({
              title: 'WORKING'
          });
      }, function(response){
        $ionicPopup.alert({
            title: ' NOT WORKING '
        });
      });
    

    回复enter image description here

    注意:$ window.localStorage ['令牌']正常运行。我尝试了很多事情,我甚至不知道我现在做错了什么,可能是语法错误,但是ERROR 403将无法显示。

    已编辑(已添加)

    响应变量enter image description here

0 个答案:

没有答案