CORS: JSONP code sample

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

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.

···

On Wed, Jun 3, 2015 at 4:09 PM, Greg Rowles greg.rowles@gmail.com 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@lists.launchpad.net

Unsubscribe : https://launchpad.net/~dhis2-devs

More help : https://help.launchpad.net/ListHelp


Morten

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 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 Wed, Jun 3, 2015 at 4:09 PM, Greg Rowles
greg.rowles@gmail.com 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@lists.launchpad.net

Unsubscribe :
https://launchpad.net/~dhis2-devs

More help :
https://help.launchpad.net/ListHelp

Morten