DINESH KUMAR
DINESH KUMAR

Reputation: 121

httpClient.get() method not fetching data

I am trying to get data using httpClient.get() method from Codeignitor API. But it is not working.

loginUser(event){
   console.log(event);
   console.log('this');
   this.httpClient.get('http://localhost/Ideabucket/idea- 
   bucket/api/index.php/Welcome/get_data').subscribe(
      (data:any[])=>{
      console.log(data.length);
   )
}

But when I call the API in browser, the data is displayed. Please help me fix this. Thanks in advance

Upvotes: 0

Views: 147

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

This is a CORS issue, solution 1:

To fix it add this at the top:

<?php  
  'header(Access-Control-Allow-Origin: *)';
  'header(Content-Type: application/json)'
?>  

Upvotes: 2

Related Questions