Error reading a RSS/JSON from my Server


#1

Hi,

I am trying to read a RSS/JSON from my own server and I am always getting this error:

{"_body":{"isTrusted":true},"status":0,"ok":false,"statusText":"","headers":{},"type":3,"url":null}

Here is my code:

import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Observable }     from 'rxjs/Observable';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

@Injectable()
export class FeedService {

  private feedUrl:string = 'http://www.myserver.com/feed/json';  

  constructor(private http: Http) {}

  getItems(): Observable<any[]> {
    return this.http.get(this.feedUrl)
                    .map(this.extractData)
                    .catch(this.handleError);
  }

  private extractData(res: Response) {
    let body = res.json();
    for (var i = 0; i < body.length; i++) {
      if ( body[i].thumbnail ) {
        body[i].thumbnail = body[i].thumbnail.split(',')[0].replace(' ', '?');
      }
      body[i].interested = localStorage.getItem(body[i].id + 'Interested') === 'true' || false;
      body[i].going = localStorage.getItem(body[i].id + 'Going')  === 'true' || false;
      body[i].ignore = localStorage.getItem(body[i].id + 'Ignore')  === 'true' || false;

      console.log('extractData', body);
    }
    return body || { };
  }

  private handleError (error: any) {
    let errMsg = (error.message) ? error.message :
      error.status ? `${error.status} - ${error.statusText}` : 'RSS Server error';
    console.error(error);
    return Observable.throw(errMsg);
  }
}

Any help, please?


#2

did you solve it? I’m also facing same in rc0.


#3

Yes, I’ve added the header (server side):
header(“Access-Control-Allow-Origin: *”);

And now its working! :slight_smile:


Http fail to get json
#4

Thanks a ton. Struggled too much to solve it, it was working in beta 11 so I thought my server is fine. Saved my half day, already wasted half :stuck_out_tongue:


#5

I am also getting this problem… How i need to solve this…??


#6

here im using a RDS on AWS, and when i try to post a json from ‘ionic running on device’ to the uri, i get the same error response…i’ve been trying to figure out how to add that header you talk about in the server side but i just cant find the answer…

Im using api gateway to get the json sent from device, and pass it to a lambda function (where i make some insert queries to insert values on mysql database)


#7

I am finding the same issue do you guys find any luck solving it ?