来自rails应用中的react组件的ajax POST请求返回一个无效的真实性令牌错误文档包含<%= csrf_meta_tags %>
$.ajax({
type: 'POST',
url: posturl,
parameters: {
authenticity_token: $('[name="csrf-token"]')[0].content,
msg_time: msg_time,
sender: sender,
sender_name: sender_name,
body: msgbody
},
success: function(res){
console.log(res);
},
error: function(err) {
console.log(err);
}
});
将parameters
改为data
$.ajax({
type: 'POST',
url: posturl,
data: {
authenticity_token: $('[name="csrf-token"]')[0].content,
msg_time: msg_time,
sender: sender,
sender_name: sender_name,
body: msgbody
},
success: function(res){
console.log(res);
},
error: function(err) {
console.log(err);
}
});