Welcome Guest, Not a member yet? Register   Sign In
CSRF with fetch API
#1

Can someone help me with this?

Code:
fetch(SITE_CONSTANT+'/login/updateUser', {
    method: "post",
    body: "Some string"
})
    .then(response => response.json())
    .then(data => data.result)
    .then(result => console.log(result));

posting stuff with fetch api from javascript to a controller. It works when I turn off csrf, but does not when it's on.

I tried to do like this:
Code:
let csrfs = document.querySelectorAll('input[name=csrf_token]');
let csrf = {name: csrfs[0].name, value: csrfs[0].value};
fetch(SITE_CONSTANT+'/login/updateUser', {
    method: "post",
    body: [csrf, {name: "a name", value: "a value"}]
})
    .then(response => response.json())
    .then(data => data.result)
    .then(result => console.log(result));

Like how I do with Jquery ajax - but still no dice Sad help?
You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply


Messages In This Thread
CSRF with fetch API - by Leo - 07-01-2020, 11:04 AM
RE: CSRF with fetch API - by MGatner - 07-07-2020, 10:26 AM
RE: CSRF with fetch API - by Leo - 07-07-2020, 12:51 PM
RE: CSRF with fetch API - by MGatner - 07-07-2020, 04:20 PM
RE: CSRF with fetch API - by Leo - 07-08-2020, 08:41 AM
RE: CSRF with fetch API - by InsiteFX - 07-08-2020, 11:40 AM



Theme © iAndrew 2016 - Forum software by © MyBB