Angular 9 + error when passing variable in direct html function

Asked

Viewed 163 times

-1

Guys, I have a question about a mistake that I don’t understand why. I have a function that I run by a click, this function has to pass a single value and is passing(tested via console.log). Function below:

  removeL(form) {
    form = { idAcesso: form };
    console.log(form); // Testado e retornando tudo certo // idAcesso: "4"
    this.passosService.postRemoveL(form).subscribe(
      data => {
        if (!data.erro) {
          window.location.reload();
        }
      });
  }

  postRemoveL(form) {
    const url = 'http://localhost:80/admecp/admegp/getLC.php?xp0d1s6to=' + this.token;
    return this.http.post<any>(url, JSON.stringify(form))
      .pipe(map(dados => {
        return dados.invalid? this.authService.gout() : dados;
      }));
  }
  console.log(JSON.stringify(form)); // "idAcesso":"4"

The problem is that it does not return the expected value, if I put the number 4 manually, it returns right this.passosService.postRemoveL('4').

If I manually put the number 4 into a variable and pass the variable, it returns correctly too. form = { idAcesso: '4'};

html code:

<a href="javascript:;" class="mr-2 text-danger" (click)="removeL(item.id)">
  <i class="fas fa-minus-circle fa-xs"></i>
</a>

And guess what, if I manually put the number 4 in HTML, it works!!! (click)="removeL(4)" .

Please, does anyone know the problem? I already tested the back with Postman and phpmyadmin, so I know that the problem is hardly in it, apart that this backend is more to test, I am not responsible for this part, but in doubt, I will post the code too.

  if($method === 'POST'){
    $body = file_get_contents('php://input');
    $text = postaDadosUsers ($_GET['xp0d1s6to'], json_decode($body, true));
    echo $text;
    exit;
  }

  function postaDadosUsers($tk, $dados){
    $id = $dados['idAcesso'];
    $link = connect ();
    if ($result = mysqli_query($link, "call adm_remvl_stu('$tk','$id')")) {
        mysqli_close($link);
        if($row = mysqli_fetch_row($result)){
            if ($row[0] == 'fr'){
                return json_encode($resp = array('invalid' => $row[0]));
            }
            return json_encode($resp = array('ok' => $row[0]));
        }
    }
  }

It returns no error. The request code is 200, but the answer is missing and the BD is not updated.

With Postman, everything works, testing in the application but entering the values manually, it also works.

What’s up? Some light? Thanks in advance!!!

1 answer

1


Guys, I got it! I don’t know what it was, except I tested it on the shampoo. I restarted all the applications and the S.O. itself and then it worked on WAMP, I believe it is some bug or failure in the installation of my system. That’s got to be it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.