在有效负载消息中发送CSRF令牌:
$('button').click(function (e) { e.preventDefault(); var text = $('.favori').val(); alert(text); $.post( "/form", { text: text, _csrf : $('meta[name="_csrf"]').attr('content') }, function (data) { console.log(data); });});为了简化您的工作,我认为您可以创建一个Jquery插件来执行此操作,如下所示:
(function( $ ) { $.postCSRF = function(to, message, callback) { message._csrf = $('meta[name="_csrf"]').attr('content'); $.post(to, message, callback); };}( jQuery ));// Usage example:$.postCSRF('/form',{text:'hi'},function(res) { console.log(res);});示例:http://jsfiddle.net/w7h4Lkxn/



