1

I'm working with React JS and symfony 4, i need to do a insert but i need a token inside the form to send it to the controller, then i get the token by ajax but i need a way that set varible, to set this token but set varible inside ajax is not working because when i send the form the variable (or the state) is empty. so how i can do it ? or if you know other way than you

PD: I speak spanish and i'm learning english so please forgive if i have some mistake, thank you

constructor:

 constructor(props) {
    super(props);
    this.state = {
        token:''
    }
 }

ajax:

   success: function(response) {

     if (response) {
         this.setState({ token: response })
     }

   },

another way

constructor(props) {
    super(props);
    this.token = '';
}

ajax:

    success: function(response) {

     if (response) {
         this.token = response;
     }

    },
YeisonM
  • 517
  • 1
  • 6
  • 18

0 Answers0