# Ionic 2 , error while fetching jsondata from host

**URL:** <https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315>\
**Category:** ionic-v3\
**Created:** [December 15, 2016, 4:12am UTC](https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315 "2016-12-15T04:12:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ABHILASH12](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@ABHILASH12](https://forum.ionicframework.com/u/ABHILASH12)\
**Post date:** [December 15, 2016, 4:12am UTC](https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315/1 "2016-12-15T04:12:24Z")

</div>

i am new to ionic 2 , now i am trying to get the data from host but facing this error .  
how can i overcome this error . thank you

`XMLHttpRequest cannot load http://example.com/jsondata . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.`

this is my ts file

```
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import {Http , Headers} from '@angular/http';
import 'rxjs/add/operator/map'

@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})

export class HomePage {

  url:string;
  data:any[];

  constructor(public navCtrl: NavController , public http : Http) {

    this.getdata();

  }

  getdata(){

    this.url="http://example.com/jsondata";

    this.http.get(this.url).map(res => res.json()).subscribe( res =>{
      console.log(res);
        this.data = res;
    }, err => {
      console.log(err);
    })

  }

}
```

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [December 15, 2016, 4:15am UTC](https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315/2 "2016-12-15T04:15:19Z")

</div>

Did you try searching the forums? There are many similar topics with detailed information on this subject.

---

<div class="post-metadata">

**Author:** ![ABHILASH12](https://avatars.discourse-cdn.com/v4/letter/a/ebca7d/32.png) [@ABHILASH12](https://forum.ionicframework.com/u/ABHILASH12)\
**Post date:** [December 15, 2016, 4:37am UTC](https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315/3 "2016-12-15T04:37:58Z")

</div>

ya i got few but it was in ionic 1 , and i am not so familiar with angular 1 , so i dint understand properly .  
and i am new to ionic 2 also , so could you please help me out .  
thank u

---

<div class="post-metadata">

**Author:** ![saintsatplay](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/saintsatplay/32/105378_2.png) [@saintsatplay](https://forum.ionicframework.com/u/saintsatplay)\
**Post date:** [December 15, 2016, 2:09pm UTC](https://forum.ionicframework.com/t/ionic-2-error-while-fetching-jsondata-from-host/73315/4 "2016-12-15T14:09:18Z")

</div>

Are you requesting the resource from your own hosted server? If so you can modify the HTTP header for the script serving the JSON like so (example taken from PHP ):

header(‘Access-Control-Allow-Origin: \*’);

This will allow access from ANY location. This might present a security risk so you could limit to a specific domain instead.

Otherwise this resource might be helpful: [http://stackoverflow.com/questions/40576037/cors-with-firebaseionic2angularjs-no-access-control-allow-origin-still-exis](http://stackoverflow.com/questions/40576037/cors-with-firebaseionic2angularjs-no-access-control-allow-origin-still-exis)
