angularjs
2015-10-17 32 views 0 likes 
0

我是编程新手,所以请耐心等待。在这里使用angularjs调用API需要一些帮助,我认为这对JSON Web令牌有一些问题;试图调用API时,我得到:使用JWT与angularjs调用API

登录对象{成功:真实,数据:对象}

对象{成功:虚假,错误:“用户没有登录

 $scope.login = function() { 
      var url = ""; 
      url = 'http://localhost.net/api/login'; 
      $.post(url, {email: "admin", password: "admin"}, function (data) 
      { 
       console.log("Login", data); 

       url = 'http://localhost.net/api/device/get'; 
       $.post(url, {}, function (data) 
       { 
        console.log("Devices", data); 
       }).fail(function (data) { 
        console.log("Devices", "login_failed"); 
       }); 

       url = 'http://localhost.net/api/async'; 
       $.post(url, {}, function (data) 
       { 
        console.log("Live Data", data); 
       }).fail(function (data) { 
        console.log("Live Data", "login_failed"); 
       }); 

       url = 'http://localhost.net/api/command/send'; 
       $.post(url, {deviceId: 2, type: "Stop"}, function (data) 
       { 
        console.log("Command", data); 
       }).fail(function (data) { 
        console.log("Command", "login_failed"); 
       }); 

      }).fail(function (data) { 
       console.log("Login", "login_failed"); 
      }); 
     }; 
+0

是否有你使用jquery post而不是angulars的原因? – Teliren

回答

1
+0

非常感谢您展示我的错误:D真的能够启发我 – and12345

0

所提供的代码显示没有实施智威汤逊的,并使用ŧ他使用jQuery Ajax系统来提出请求。知道“智威汤逊问题”在哪里是令人困惑的。你使用angular-jwt吗?如果是通过$ http提供的自动标记处理,而不是$ .ajax,这可能是您的问题。有关该库实施的更多信息can be found here

如果不是这种情况,我建议查看实施described here

相关问题