Error reading a RSS/JSON from my Server

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?

did you solve it? Iā€™m also facing same in rc0.

Yes, Iā€™ve added the header (server side):
header(ā€œAccess-Control-Allow-Origin: *ā€);

And now its working! :slight_smile:

2 Likes

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:

1 Like

I am also getting this problemā€¦ How i need to solve thisā€¦??

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)

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

I used this code:
Server side: header(ā€œAccess-Control-Allow-Origin: *ā€);
Client side: let headers = new Headers({ ā€œContent-Typeā€: ā€œapplication/x-www-form-urlencodedā€ });
And the problem was solved

Instead of doing this, I would recommend making your request body a URLSearchParams, at which point HttpClient will set the content type header properly for you.