Partage
  • Partager sur Facebook
  • Partager sur Twitter

HttpErrorResponse {headers: HttpHeaders, status: 4

Not Found", url: "http://127.0.0.1:8000/api/studentbyid//undefined"

4 décembre 2019 à 5:48:09

Hi!, i have a little worry, if some can just help me, i use a laravel 5.8 api, which i create, when i retrieve the parameter data mtr from posteman its walk, but when i do the same thing with this url << url = 'http://127.0.0.1:8000/api/studentbyid/45' >> it works its problem because the 45 is the mtr, whereas according to the logic that I try to put in place and that it is the user who will introduce the mtr, then display...
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
    import { Component, OnInit } from '@angular/core';
    import { HttpClient } from '@angular/common/http';
    import { Candidate } from '../models/candidate';
    @Component({
      selector: 'app-candidate',
      templateUrl: './candidate.page.html',
      styleUrls: ['./candidate.page.scss'],
    })
    export class CandidatePage implements OnInit {
      mtr: '45';
      // tslint:disable-next-line: new-parens
      data: any;
      url = 'http://127.0.0.1:8000/api/studentbyid/';
      constructor( private httpClient: HttpClient) { }
      ionViewWillEnter(mtr: string) {
        return this.httpClient.get(this.url + '/' + this.mtr)
        .subscribe(data => {
          this.data = JSON.stringify(data);
          console.log(this.data);
     }), error => {
        console.log(error);
    };
       }
      ngOnInit() {}
      getbyID( mtr: string) {
      }
    }
<!-- end snippet -->
here is the result in the console when I place it directly
and that's when I try to retrieve the word from a user
if there are some who can just help me, and I notice that there is no answer in the form of object
  • Partager sur Facebook
  • Partager sur Twitter
4 décembre 2019 à 14:21:29

Hi. Please use code editor to paste your code (button </> and choose "Jscript"). Anyways, you see that you are targetting a wrong url, "http://127.0.0.1:8000/api/studentbyid//undefined" instead of "http://127.0.0.1:8000/api/studentbyid/45".

return this.httpClient.get(this.url + '/' + this.mtr)
// You doesn't need another '/', so it's just
return this.httpClient.get(this.url + this.mtr)


And you must initialize "mtr" this way

mtr:string = '45';



-
Edité par kulturman 4 décembre 2019 à 14:22:24

  • Partager sur Facebook
  • Partager sur Twitter