[英]Set session cookie in login using ajax
I am using AJAX to login to the server. 我正在使用AJAX登录到服务器。 For API calls the server uses session authentication. 对于API调用,服务器使用会话身份验证。 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 使用像这样的库来设置cookie并在每次需要时获取它
$.setCookie("sessionId",value);
$.getCookie("sessionId"); // returns value
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.