• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to fix error 403 when csrf enabled with ajax

#3
The browser developer tool is your best friend

You cannot use a variable as an object property name when writing code like this.
 data: {csrfName: csrfHash }  

Use like this

let data = {}
data[csrfName] = csrfHash


and than

$.ajax({ .... data : data 

Or you can send the header in the request.

let csrfHeader = '<?=csrf_header() ?>'

$.ajax({ 
url : 'some-url',
beforeSend: function(request) {
  request.setRequestHeader(csrfHeader, csrfHash);
},
data : { key : value },
....

(01-13-2021, 02:52 PM)onebuyu Wrote: I solved it by adding angle blackets "[]"to the data key like this:
Code:
data: {[csrfName]: csrfHash },

Interesting. Thx. I didn't know anything about computed properties.
Reply


Messages In This Thread
RE: How to fix error 403 when csrf enabled with ajax - by iRedds - 01-13-2021, 04:51 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.