Dynamo

waltd

24 May 2015, 11:13 pm

JSONP for cross-domain JavaScript access

I found a really cool site called PlainJS (http://plainjs.com), and within it a great trick for requesting data cross-domain called JSONP. I’d heard of this before, but never tried it out.

Here’s the code I used: https://gist.github.com/walterdavis/5bc16f569929d76993c9

I made a simple Rails app to handle the JSON reply and to populate the database. Because I was running Rails locally, it was hosted at localhost:3000, and I hosted my test HTML page using Apache, so it was at al.local/api. Even though an Ajax request from al.local to localhost:3000 fails on two counts (host and port) to be from the Same Origin, this just works. I can add a new widget and see it reflected on the HTML page.

Walter

Freeway user since 1997

http://www.walterdavisstudio.com

Joe Billings

29 May 2015, 9:50 am

That’s very neat.

Joe Billings

Freeway & Exhibeo: Visual web design apps for Mac


http://www.softpress.com