0

Using my jsonp call below, I get an error Response with status: 200 Ok for URL. If I understand correctly, this means that my get request actually worked. However, my method of calling the data didn't. You may find the link to my data either below, or by clicking this link.

constructor(private jsonp: Jsonp){}
stockrun(){

this.jsonp.get('http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=myRun')
    .map(res => res.json())
    .subscribe((information) =>{
     console.log(information);
    });

}

The reason I entered myRun into the URL is because the data is organized differently when there is no callback, like in http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL.

I would also like to add that without myRun I get only the error 200 code. With it however, I also get cannot find name myRun.

Noémi Salaün
  • 4,866
  • 2
  • 33
  • 37
abrahamlinkedin
  • 467
  • 1
  • 6
  • 23

2 Answers2

0

Got the answer from this question. Basically,

var url = 'http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=JSONP_CALLBACK';
this.jsonp.get(url)
.map(res => res.json())
.subscribe(data => console.log(data));
Community
  • 1
  • 1
abrahamlinkedin
  • 467
  • 1
  • 6
  • 23
0

Your response is not JSON. It's encapsulated inside myRun(...), so to unserializing it, you should call something like

this.jsonp.get('http://dev.markitondemand.com/MODApis/Api/v2/Quote/jsonp?symbol=AAPL&callback=myRun')
    .map(res => {
        // Get raw text instead of parsed object.
        let text = res.text();

        // Removing myRun().
        text = text.substring(6, text.length - 1);

        // Return manually parsed response.
        return JSON.parse(text);
    })
    .subscribe((information) =>{
        console.log(information);
    });

to remove myRun( and the last ).

You will have to call res.text() instead of res.json(), then substring the result and then call JSON.parse()

Noémi Salaün
  • 4,866
  • 2
  • 33
  • 37