← Back to team overview

dhis2-devs team mailing list archive

Re: CORS: JSONP code sample

 

Hey Greg,

CORS and JSONP are not going to work together. As you can't really add any authentication headers to the JSONP request. Not in the "default" way. As JSONP is pretty much just a fancy way of doing a <script> tag.

You could do a normal GET with CORS and then eval() the response, if for whatever reason you really need to do JSONP. But if you're just trying to get some data when using CORS then just use normal JSON like Morten suggested.

Regards,

Mark

On 3 Jun 2015, at 11:19, Morten Olav Hansen <mortenoh@xxxxxxxxx<mailto:mortenoh@xxxxxxxxx>> wrote:

Hi Greg

I don't have an example here, but all you really need to do is to add a Authotization header (to your $.ajax or what you are using) and it should work, I havent played around with credentials directly (but this is also probably supported? I know jquery have withCredentials etc)

What is important is that you add the domain where the request is coming from to the CORS whitelist (system settings, remove access), if will not work if you don't do this.

Btw, since you are using CORS, you don't need to use JSONP, you can just use JSON/XML as normal.

--
Morten

On Wed, Jun 3, 2015 at 4:09 PM, Greg Rowles <greg.rowles@xxxxxxxxx<mailto:greg.rowles@xxxxxxxxx>> wrote:
Hi Devs

I'm testing JSONP capabilities against version 2.19 but struggling a little to be honest. Does anyone have a code sample that works against the demo instance or similar?

Thank you,
Greg

--
Health Information Systems Program - South Africa
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Mobile  :    073 246 2992
Landline:   021 554 3130
Fax:          086 733 8432
Skype:      gregory_rowles

_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx<mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp


_______________________________________________
Mailing list: https://launchpad.net/~dhis2-devs
Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx<mailto:dhis2-devs@xxxxxxxxxxxxxxxxxxx>
Unsubscribe : https://launchpad.net/~dhis2-devs
More help   : https://help.launchpad.net/ListHelp


References