【发布时间】:2015-05-02 19:51:57
【问题描述】:
为了将授权令牌(应该存储在数据库中)发送到我的服务器,我在 .scala.html 文件中进行了 AJAX 调用。
$.ajax({
url: "http://localhost:9000/storeauthcode",
type: 'get',
data: {code: authResult['code']},
contentType: 'application/json',
dataType: 'json',
success: function(result) {
// Handle or verify the server response.
console.log("you're fully logged in now.")
console.log(JSON.stringify(result, null, 2))
console.log("document.cookie = "+document.cookie)
},
error: function (xhr, status, error) {
console.log("error\n")
console.log(xhr.responseText)
}
});
}
在服务器端,我存储验证码并返回一个 json 响应
def storeAuthCode = Action { request =>
//store credentials in database
//...
//return some data
Ok(Json.toJson(Map("a"->"b"))).withSession("code"-> "someAuthCode", "id"->"someId")
}
如果我尝试通过 AJAX 调用的成功处理程序打印所有 cookie
console.log("document.cookie = "+document.cookie)
document.cookie 似乎是空的,尽管服务器应该已经创建了一个会话 Cookie(或至少任何东西)。 document.cookie 应该返回一个“;”我的 Cookie 值的分隔列表。
如何才能成功设置我的 Cookie?
【问题讨论】:
标签: ajax scala session cookies playframework