国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

angular.js - The backend is based on JWT verification. How does Angular post request carry token?
曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新 2017-05-16 13:18:00
0
3
860

Get the token returned by the backend after the user successfully logs in

userService.loginUser(user).then(
function(response) {
    $cookies.put("token", response.token)
                    ...

Then, how to carry this token when updating personal information?

token = $cookies.get("token")
console.log(token)
studentService.edit(token).save({studentId: $scope.student.id}, student,
    function(response) {
        console.log(response)

studentService

angular.module('app')
    .factory('studentService', [
        '$resource',
        function($resource) {
            return {
                detail: function() {
                    return $resource('/api/student/:studentId/ ', {
                        studentId: '@studentId'
                    })
                },
                edit: function(token) {
                    return $resource('/api/student/:studentId/edit/ ', {
                        studentId: '@studentId'
                    },{headers: { 'auth-token': token }})
                }
            }
        }
    ]);

I did this, but it still shows that the verification failed.

曾經(jīng)蠟筆沒有小新
曾經(jīng)蠟筆沒有小新

reply all(3)
PHPzhong

{withCredentials:true} Popular science connection

劉奇

Thank you for the invitation. It is not convenient to send specific article links on mobile phones. Mainly to give you ideas.
After logging in, you need to bring a token with each request. Generally, this function is achieved by adding custom request headers, and AngularJS 1.x provides interceptors. It is also recommended that you also search for MDN CORS related information and $resource related documents.
There are many application examples of AngularJS 1.x and JWT abroad. It is recommended that you search on Google.

phpcn_u1582

Use angularjs-jwt and add token to each request header. Reference: github address https://github.com/auth0/angu...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template