Welcome Guest, Not a member yet? Register   Sign In
CSRF giving problem with ajax
#6

(05-06-2015, 07:20 AM)matbeard Wrote: I use CSFR protection on my site which is massively Ajaxified. I use a jquery plugin (https://github.com/carhartl/jquery-cookie) that makes handling cookies simple:
<script>
var csrf_token = $.cookie('csrf_token');
</script>

Then whenever I'm POSTing data with Ajax, I just need to include the csrf_token in the data object that's sent to the CI server.

Works really well.

I do the same. massive AJAX usage on CI3, with token refreshing on every request.

So i added this to my footer:

Code:
    $(document).ready(function () {
        $('form').submit(function () {
        var csrf_cookie_val = $.cookie(csrf_cookie_name_goes_here);
        $(this).find('input[type="hidden"]')
            .filter('[name="' + csrf_var_name_goes_here + '"]')
            .val(csrf_cookie_val);
        });
    });
Reply


Messages In This Thread
CSRF giving problem with ajax - by tancredolt - 05-02-2015, 09:52 PM
RE: CSRF giving problem with ajax - by prabhakar - 05-03-2015, 06:25 AM
RE: CSRF giving problem with ajax - by PaulD - 05-04-2015, 09:06 AM
RE: CSRF giving problem with ajax - by matbeard - 05-06-2015, 07:20 AM
RE: CSRF giving problem with ajax - by josetrindade - 05-29-2015, 04:27 AM
RE: CSRF giving problem with ajax - by tancredolt - 05-29-2015, 12:45 AM
RE: CSRF giving problem with ajax - by techbat - 05-29-2015, 05:56 AM
RE: CSRF giving problem with ajax - by kintech - 09-30-2019, 05:16 AM
RE: CSRF giving problem with ajax - by albertleao - 09-30-2019, 08:36 AM



Theme © iAndrew 2016 - Forum software by © MyBB