i am running my django on localhost i.e http://127.0.0.1:8000/stocks/ this url returns JSON Data as shown below:
[
{
"id": 1,
"ticker": "FB",
"open": 7.0,
"close": 10.0,
"volume": 500
},
{
"id": 2,
"ticker": "AMZN",
"open": 125.05,
"close": 200.98,
"volume": 800
},
{
"id": 3,
"ticker": "MSFT",
"open": 1.25,
"close": 87.0,
"volume": 7000
}
]
i am using a provider in my app to get the data from the url
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Injectable()
export class GetData {
public data:any;
constructor(public http: Http) {
console.log('Hello GetData Provider');
}
load(){
if (this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.http.get('http://127.0.0.1:8000/stocks/')
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
}
this provider i am using in my page to receive the data and show
import { Component } from '@angular/core';
import {GetData} from '../../providers/get-data';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
public recvData:any;
constructor(public navCtrl: NavController, public getData: GetData) {
this.loadPeople();
}
loadPeople(){
this.getData.load()
.then(data => {
this.recvData = data;
});
console.log("the received data is >> ",this.recvData);
}
}
and using it in my html page like this
<ion-content padding>
<ion-list>
<ion-item *ngFor='let stock of recvData'>
<p>stock.ticker</p>
</ion-item>
</ion-list>
</ion-content>
and i am getting this error:
XMLHttpRequest cannot load http://127.0.0.1:8000/stocks/. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100’ is therefore not allowed access.
main.js:43460EXCEPTION: Response with status: 0 for URL: null
please help…thanks in advance