根据带有凭据的请求,Firefox只会发送凭据以及跨域帖子
invocation.withCredentials = "true";
设置...但似乎jQuery的Ajax API没有为此提供任何机制.
有没有我错过的东西?还有其他方法可以做到吗?
我使用 axios 从 ReactJS 客户端向 Node.js 服务器发送请求,如下所示。
import axios from 'axios';
const apiClient = axios.create({
withCredentials: true,
baseURL: 'http://localhost:8080'
});
async function(payload) {
try {
debugger;
let result = await apiClient.post('/auth/signup/', payload);
debugger;
return result;
} catch (error) {
debugger;
throw error;
}
}
Run Code Online (Sandbox Code Playgroud)
Node.js 端点在响应中设置一个 cookie,如下所示。
const express = require('express');
const bodyParser = require('body-parser');
const cookieParser = require('cookie-parser')
const cors = require('cors');
const jwt = require('jsonwebtoken');
router.use(bodyParser.json());
router.use(bodyParser.urlencoded({ extended: true }));
router.use(cors({ origin: 'http://localhost:3000', credentials: true, exposedHeaders: ['Set-Cookie', 'Date', …Run Code Online (Sandbox Code Playgroud) 当用户第一次访问特定页面时,我正在显示jQuery叠加层
他们在叠加层中有一个单选按钮,他们可以点击它们说他们不希望再次看到通知
我想设置一个用户不想再看到叠加层的cookie
是否可以在不刷新页面的情况下设置cookie?
我打算将ajax调用回服务器,然后在响应头中设置cookie,但我猜他们不会在Ajax请求/响应中设置?
纯粹从javascript设置cookie是安全/可以的吗?或者这是一个坏主意?
还有其他选择吗?
cookies ×2
cross-domain ×2
javascript ×2
asp.net-mvc ×1
axios ×1
jquery ×1
node.js ×1
reactjs ×1