AJAX 响应可以设置 cookie 吗? [英] Can an AJAX response set a cookie?

查看:41
本文介绍了AJAX 响应可以设置 cookie 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AJAX 响应可以设置 cookie 吗?如果没有,我的替代解决方案是什么?我应该用 Javascript 或类似的东西设置它吗?

Can an AJAX response set a cookie? If not, what is my alternative solution? Should I set it with Javascript or something similar?

推荐答案

,您可以在服务器端代码的 AJAX 请求中设置 cookie,就像您对普通请求所做的一样因为服务器无法区分普通请求或 AJAX 请求.

Yes, you can set cookie in the AJAX request in the server-side code just as you'd do for a normal request since the server cannot differentiate between a normal request or an AJAX request.

AJAX 请求只是向服务器发出请求的一种特殊方式,服务器需要像在任何 HTTP 请求中一样进行响应.在请求的响应中,您可以添加 cookie.

AJAX requests are just a special way of requesting to server, the server will need to respond back as in any HTTP request. In the response of the request you can add cookies.

这篇关于AJAX 响应可以设置 cookie 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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