WARNING: Can't verify CSRF token authenticity rails

后端 未结 17 1310
生来不讨喜
生来不讨喜 2020-11-22 06:05

I am sending data from view to controller with AJAXand I got this error:

WARNING: Can\'t verify CSRF token authenticity

I think

17条回答
  •  情书的邮戳
    2020-11-22 06:29

    For those of you that do need a non jQuery answer you can simple add the following:

    xmlhttp.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
    

    A very simple example can be sen here:

    xmlhttp.open("POST","example.html",true);
    xmlhttp.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
    xmlhttp.send();
    

提交回复
热议问题