【发布时间】:2018-01-03 22:34:31
【问题描述】:
我需要为 HTTP 请求设置 cookie。
有可能做这样的事情吗?
$.ajax({
method: "POST",
url: "http://example.org/",
dataType: "html",
data: {
game: "soccer",
value: "2395",
action: "newGame"
},
cookies: {
"domain": ".example.org",
"name": "SESSION",
"path": "/",
"value": "34645645765756757"
}
}).done(function( msg ) {
console.log(msg);
});
【问题讨论】:
-
不,这是不可能的。它会发送
document.cookie中的任何 cookie(假设 URL 在同一个域中)。 -
如果您想发送 cookie,只需将它们作为参数或标头发送即可。
标签: javascript jquery cookies httprequest