Reputation: 37
I have this code:
login: any;
constructor(private http: HttpClient) { }
ngOnInit() {
this.http.get("http://localhost:8000/login/list")
.subscribe(
resultado => {
this.login = resultado;
document.write(this.login);
}
);
}
I tried to get data from a JSON located on the web and I got the data! However, when I try to get it from the localhost server (which is running a PHP application and returning JSON) it doesn't seems to work. I tried to open the URL on the web browser and it does actually return a JSON.
Any clue on what's going on?
Upvotes: 0
Views: 95
Reputation: 37
Problem was CORS.
Adding this to my PHP project made it work:
composer req cors --ignore-platform-req=ext-http
Upvotes: 1