1

Angular 12 - Httpclient jsonp - how to pass custom callback parameter?

Here is the full app -> https://stackblitz.com/edit/angular-ivy-2zg5yt?file=src/app/geolocation.service.ts

geolocation-service.ts

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

@Injectable({
  providedIn: 'root'
})
export class GeolocationService {
  constructor(private httpClient: HttpClient) {}

  getLocation(): Observable<any> {
    return this.httpClient
      .jsonp<any>('https://geolocation-db.com/jsonp', 'callback')
      .pipe();
  }
}

Gives the following error:

enter image description here

How to change the callbackparam value to be - https://geolocation-db.com/jsonp?callback=callback but angular is defaulting it to https://geolocation-db.com/jsonp?callback=ng_jsonp_callback_1

1 Answer 1

1

Turns out this is not an issue in Angular Httpclient jsonp implementation. Instead, it is an issue in the https://geolocation-db.com/jsonp. which does not dynamically update the callback function name.

The same example works like a charm with http://ip-api.com/json

Sign up to request clarification or add additional context in comments.

1 Comment

I think this is the actual Angular/JSONP answer across the board. Submitting a MailChimp form worked one time then never again.

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.