2

I'm trying to fetch de data the URL below:

http://storage.googleapis.com/nacleanopenworldprodshards/Nations_cleanopenworldprodeu1.json

I'm using Angular 9, and this is my service.ts:

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';



@Injectable({
  providedIn: 'root'
})
export class NationsService {

  constructor(private http: HttpClient) { }

  getData() {
    const url = 'http://storage.googleapis.com/nacleanopenworldprodshards/Nations_cleanopenworldprodeu1.json';

    return this.http.jsonp(url, 'callback');
  }

}

Simple enough, right? but it doesn't work. Because the "API" doesn't have a callback function. I searched a lot in stackoverflow but I did not find how to solve this.

Does anybody knows of a way to get the data using Angular 9?

Thanks you very much!

5
  • Does this answer your question? Angular jsonp calls Commented Aug 15, 2020 at 20:29
  • The URL from where you are fetching data doesnt return a valid JSON, make sure it returns a valid JSON object. Commented Aug 15, 2020 at 20:29
  • @R.Richards thanks for your answer, but I actually tested my code with other jsonp APIs and the code is working fine for them. It is only for this specific API from my original post that it doesn't work. And I'm not sure what should I do to make it work. Commented Aug 16, 2020 at 4:50
  • @KamranKhatti I don't have access to change the content of the URL unfortunately. Commented Aug 16, 2020 at 4:52
  • @PedroSaad if API returns error and we dont have access to fix that API error then how come we fix it from front end? If you dont have access to change then tell someone to fix it who has access of it no other solution. Commented Aug 16, 2020 at 8:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.