如何确保Cookie在新请求之前设置? [英] How to make sure the Cookie is set before a new request is made?

查看:150
本文介绍了如何确保Cookie在新请求之前设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题,应该在服务器端修复,但在客户端一个快速解决方法是可以接受的。



我需要在加载网页并且已设置仅http安全Cookie 后进行JS调用。我正在使用 window.onload 事件调用< a href =https://developer.mozilla.org/en-US/docs/Web/API/Location.replace =nofollow> window.location.replace(),但即使页面加载了 SET-COOKIE HTTP响应标头,则新请求不会发送


class =h2_lin>解决方案

适用于Chrome,FF和IE8 +的解决方法是使用 setTimeout()。我正在寻找更好的解决方案和解释,虽然...



谢谢,


I have an issue that should be fixed on the server side, but a quick workaround on the client side would be acceptable.

I need to make a JS call after the page is loaded and the http-only secure cookie is already set. I'm using window.onload event to call window.location.replace(), but even though the page is loaded with the SET-COOKIE HTTP response header, the new request doesn't send the cookie.

How to make sure the Cookie is set before a new request is made?

解决方案

A workaround that works for Chrome, FF and IE8+ is to use a setTimeout() inside the window.onload event handler. I'm looking for a better solution and an explanation, though...

Thanks,

这篇关于如何确保Cookie在新请求之前设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆