0

All is in the question.

I have to use an API that only lets me make requests with angular using $http.jsonp. I get the response correctly from the server, but angular considers that the request fails as I'm not using callback=JSON_CALLBACK. And when Im adding the callback in the request, the server send me back an error 500 as it doesn't allow any other parameters than the ones in the docs.

What can I do? Im at a loss

Thanks

1 Answer 1

1

In order for JSONP to work it requires server-side support. If the API you are using does not provide any support for JSONP than you simply cannot use JSONP.

In order for JSONP to work the server must wrap the JSON it returns in a function call. Usually, an API that supports JSONP will have some sort of way of passing the name of a function it can use as a callback. This is not standard, and each API might have a different way to specify the callback. If the API doesn't support specifying a callback, than you are really out of luck.

The only other thing I can think of is if the server the API is on supports CORS. CORS is a better alternative than JSONP for making cross-domain requests, but only works on modern browsers.

The only other alternative is to have your own server proxy the request on behalf of the browser. This has the downside that all traffic to that third-party API must travel through your own application's domain.

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

3 Comments

Ultimately I need to make a "simple" GET request to that server, but for some reasons, $http.get() did not work as the server sent back a 500 error. I'm trying to talk to support but nothing so far. Thanks for your explaining. Will accept if nothing better comes up
Is the server in the same domain as your application? If not, then the $http.get() will not work unless both the server and your browser support CORS. If this is a third-party library that is meant to be used from different domains then they almost surely support JSONP. They just need to tell you how to send the callback in your request.
no it's a third party. It's the Withings API link I'm really not sure that they support JSONP. I think, also, that they expect server-to-server communication rather than server-to-client comm... So I might end up having to setup my own server somewhere...

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.