I have encountered this just recently and this just solved the problem. Add the codes below to your application.js
function CSRFProtection(xhr) {
var token = $(‘meta[name="csrf-token"]‘).attr(‘content’);
if (token) xhr.setRequestHeader(‘X-CSRF-Token’, token);
}
if (‘ajaxPrefilter’ in $) $.ajaxPrefilter(function(options, originalOptions, xhr) { CSRFProtection(xhr); });
else $(document).ajaxSend(function(e, xhr) { CSRFProtection(xhr); });
function CSRFProtection(xhr) { var token = $(‘meta[name="csrf-token"]‘).attr(‘content’); if (token) xhr.setRequestHeader(‘X-CSRF-Token’, token);}if (‘ajaxPrefilter’ in $) $.ajaxPrefilter(function(options, originalOptions, xhr) { CSRFProtection(xhr); });else $(document).ajaxSend(function(e, xhr) { CSRFProtection(xhr); });
Hope this helps
