javascript 将 cookie 传回服务器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13718337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:35:52  来源:igfitidea点击:

Pass cookie back to the server

javascriptjquerycookies

提问by jonathanmarvens

I am writing a single-page application with CanJS. For one of models, every time I save a new item, the application sends the normal POSTrequest. However, there is a specific cookie that is returned in the HTTPresponse that I would like to send back to the server on GETrequests when fetching an item.

我正在用 CanJS 编写一个单页应用程序。对于其中一个模型,每次我保存一个新项目时,应用程序都会发送正常POST请求。但是,在HTTP响应中返回了一个特定的 cookie,我想GET在获取项目时根据请求将其发送回服务器。

采纳答案by rai.skumar

All cookies specific to an application are passed automatically to server in request header. Make sure that the cookie which you want to send is of the same application.

特定于应用程序的所有 cookie 都会在请求标头中自动传递到服务器。确保您要发送的 cookie 是同一个应用程序

This you can check by looking into the cookies of your browser. Make sure that the cookie which you want to send has Domainas your application name. Like all stackoverflow cookie will have domain value as .stackoverflow.com

您可以通过查看浏览器的 cookie 来检查这一点。确保您要发送的 cookie 将作为您的应用程序名称。像所有 stackoverflow cookie 一样,域值为.stackoverflow.com

You can refer to this tutorial which talks about creation and setting of cookie in JavaScript : http://www.w3schools.com/js/js_cookies.asp

你可以参考这篇关于在 JavaScript 中创建和设置 cookie 的教程:http: //www.w3schools.com/js/js_cookies.asp