rails - InvalidAuthenticityToken for json/xml requests

后端 未结 6 1301
清歌不尽
清歌不尽 2020-12-15 05:08

For some reason I\'m getting an InvalidAuthenticityToken when making post requests to my application when using json or xml. My understanding is that rails should require an

6条回答
  •  轮回少年
    2020-12-15 05:30

    Adding up to andymism's answer you can use this to apply the default inclusion of the TOKEN in every POST request:

    $(document).ajaxSend(function(event, request, settings) {
        if ( settings.type == 'POST' ||  settings.type == 'post') {
            settings.data = (settings.data ? settings.data + "&" : "")
                + "authenticity_token=" + encodeURIComponent( window._token );
        }
    });
    

提交回复
热议问题