React does not accept my post parameters

0

I have a problem I am working with codeigniter of the% backend and react % of the frontend . I am working with login, it is the first time I have to work with react, as it says in the documentation as I have done it, the request is satisfactory:

export function PostData(type, userData){

let BaseURL = 'http://...';
return new Promise((resolve, reject) =>{

    console.log(JSON.stringify(userData));

    fetch(BaseURL+type, {
        method: 'POST',
        body: JSON.stringify(userData)
        //body: formdata(userData)
      })
      .then((response) => response.json())
      .then((res) => {
        resolve(res);
      }) 
      .catch((error) => {
        reject(error);
      });


  });
}

Log console:

{"email":"d","password":"d"} //Parametros a enviar
{success: false, message: "Ingresa un usuario y una clave"} //Respuesta de API

You can see that the data is really good, you are sending it, but it returns me a false

Codeigniter
$correo = $this->input->post('email');
$clave = $this->input->post('password');

        if(isset($correo) && isset($clave)){
            if($this->Modelusers->userLogin($correo,$clave) != false){
                 $data = array (
                'success' => true,
                'message' => 'access',
                'response' => $this->Modelusers->userLogin($correo,$clave)
                );
            }else{
                 $data = array(
                'success' => false,
                'message' => 'Al parecer el usuario y la clave no son correctos'
            );
            }

        }else{
            $data = array('success'=>false,'message' => 'Ingresa un usuario y una clave');
        }
        echo json_encode($data);

I had no problem using this endpoin echo Postman executes it correctly.

From the button login login call:

login(){
       PostData('access', this.state).then ((result) => {
            let responseJSON = result;
            console.log(responseJSON);
       });
    }
  

Does anyone know why he is not receiving the parameters correctly?

    
asked by DoubleM 18.07.2018 в 17:43
source

0 answers