简体   繁体   中英

Set session cookie in login using ajax

I am using AJAX to login to the server. For API calls the server uses session authentication. How do I set the browser session from a login response?

$http({ method: 'POST',
            url: API_URL+'/signin',
            data: $scope.loginData
        }).
        success(function(data, status, headers, config) {
          //I want to set the browser session here
          // In postman I see a cookie which contains sessionId
        }).
        error(function(data, status, headers, config) {
          console.log(data);
        });

It's a cross domain request as the server allows that

Use a library like this one to set a cookie and get it everytime you need like this

$.setCookie("sessionId",value);

$.getCookie("sessionId"); // returns value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM