1. html
<%= hidden_field_tag :authenticity_token, form_authenticity_token, id: 'this id' %>
2. js
var csrf = $("input#this id").val();
headers: {
'X-CSRF-Token': csrf
}
# the headers set in ajax
本文介绍了如何在网页应用中使用隐藏字段来实现跨站请求伪造(CSRF)的防御,并展示了如何在JavaScript中获取该隐藏字段的值以设置合适的HTTP头部信息。
1. html
<%= hidden_field_tag :authenticity_token, form_authenticity_token, id: 'this id' %>
2. js
var csrf = $("input#this id").val();
headers: {
'X-CSRF-Token': csrf
}
# the headers set in ajax

被折叠的 条评论
为什么被折叠?
