Skip to content

Cross domain ajax using JSONP #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jwestbrook opened this issue May 7, 2014 · 12 comments
Open

Cross domain ajax using JSONP #197

jwestbrook opened this issue May 7, 2014 · 12 comments

Comments

@jwestbrook
Copy link
Collaborator

previous lighthouse ticket #333
by Christopher Thomas


we should definitely look at how to port jquery's getJSON() method because it's just a very simple and easy way to obtain information from another website, without messing around building your own script handler.

I believe there was an attempt to make a <script> transport for prototype, to a degree, it worked, however it lacked the ability to use a callback when the contents of the tag were finally loaded (when usually you'd expect an onload event, there is none, so the callback method for JSONP allows you to insert a callback so when it executes, it's because the contents has loaded (otherwise the callbac wouldnt run either). The sample implementation that I tried was this:

http://ajaxian.com/archives/prototype-extension-dynamic-script-pattern-support

but it is not foolproof and with some work, it could provide us with a

The security problems this causes are merely in the hands of the developer if they should choose to use it, like in jquery, it's a gun, you point it at your website, or at your head, where you pull the trigger, is up to you. But I think this feature would really rock.</p>

@jwestbrook
Copy link
Collaborator Author

Juriy Zaytsev
September 10th, 2008 @ 03:46 AM

I think such functionality is definitely useful. The content becomes more dynamic and "mashups" - more popular. Having a robust way of fetching JSON from remote hosts is a must.
Feel free to submit patch/tests.
I'm marking it as enhancement for future releases.

@jwestbrook
Copy link
Collaborator Author

Juriy Zaytsev
October 7th, 2008 @ 06:22 AM

I was experimenting with this some time ago http://github.com/kangax/protolicious/tree/master/get_json.js
Does anyone else have a working example? Are there any caveats to watch for?

@jwestbrook
Copy link
Collaborator Author

Kyle Simpson
May 22nd, 2009 @ 06:12 PM

I've just added a plugin for Prototype to use flXHR (http://flxhr.flensed.com) for cross-domain Ajax. Since flXHR is completely the same API as native XHR, it just plugs right in and works exactly like regular Ajax calls -- no other code changes needed.
Here's the Prototype plugin, called flXHRproxy: http://flxhr.flensed.com/prototype.php
Since it's just like XHR, it can do JSON, JSONP, XML, HTML, text, even binary as requests and responses. And all with cross-domain Ajax that just couldn't get any simpler.

@jwestbrook
Copy link
Collaborator Author

Valery
June 18th, 2009 @ 08:20 PM

friends, so, there is still no JSONP for PrototypeJS?..
@kyle, did I correctly understand, that your solution needs Flash?

@jwestbrook
Copy link
Collaborator Author

Juriy Zaytsev
June 22nd, 2009 @ 07:20 PM

@valery Did the script from "protolicious" work for you?

@jwestbrook
Copy link
Collaborator Author

Dan Dean
July 15th, 2009 @ 12:32 AM

@Juriy: Is the core team still interested in adding this to Prototype? If so, would this be a suitable solution? It's based on a gist by Tobie Langel with some added functionality for various phases of the life cycle, including onFailure.
http://gist.github.com/147172
Better testing is needed, as well as some input as to whether this should hook into the Ajax.Responders callbacks.

@jwestbrook
Copy link
Collaborator Author

Dan Dean
July 15th, 2009 @ 05:15 AM

I've added this feature to Github along with documentation and explanation:
http://github.com/dandean/Ajax.JSONRequest

@jwestbrook
Copy link
Collaborator Author

Kyle Simpson
September 8th, 2009 @ 05:05 AM

I've also got another project for doing simple JSON-P cross-domain calls via the XHR API interface: jXHR http://mulletxhr.com
It works just like the native XHR object, but uses JSON-P style script tags to make the calls (so it doesn't rely on flash like flXHR does). It also adds basic error handling to the calls.

@jwestbrook
Copy link
Collaborator Author

ronin-24025 (at lighthouseapp)
September 9th, 2009 @ 04:28 PM

I did a ton of research on cross-domain ajax: flash-based techniques, JSONP, proxying techniques, Kris Zyp's WindowNameRequest technique. Executive summary:
FLASH:
Proprietary.
JSONP:
Requires support from server. Limits POST request (if supported) representation size to 4kb.
Proxy:
Requires proxy server.
WindowNameRequest:
Requires support from server. Limits POST request (if supported) representation size to 10mb.
A primitive and more complex version of WindowNameRequest was used by Google last year. Kris Zyp's version subsequently improved and simplified it: http://www.sitepen.com/blog/2008/07/22/windowname-transport/

@jwestbrook
Copy link
Collaborator Author

Amit Kumar
June 10th, 2010 @ 10:22 PM

Hey... so what's the status on the Ajax.JASONRequest.??
The whole idea of JASONP looks more like a workaround, but alas there is not other easier way.
Clearly there is a need for this and I would request to take it on priority. As mentioned above , JQuery already one.
I was interested in making a traffic monitoring mashup through twitter messages, and google maps api. After going through Crockford's JS tutorial videos, really wanted to make it javascript, thereby moving everything into a nifty javascript code which in turn could be pasted by anyone in his html page.
Unfortunately there aren't many javascript libraries for twitter. I have been working with Prototype for past few years, so being a faithful, wanted to give it a try first. But looks like the cross-domain restriction is a big roadblock for mash-up in a client-side processing environment.
And I think we should also work to make a twitter library through Prototype. But before that we really need some kind of JASONP implementation.
Regards
-AK

@jwestbrook
Copy link
Collaborator Author

Jason Laumeister
December 8th, 2010 @ 02:18 AM

I've had success with prototype 1.6.1 and Dan Dean's jsonp implementation here: https://github.com/dandean/Ajax.JSONRequest
Dan Dean's implementation is < 120 lines of javascript (< 3.9k).
jsonp is a necessary work-around for cross-domain restrictions that would otherwise prohibit a page from making an ajax call to a third party server. A real-world example would be an online game that includes ads in an DHTML popup from a third party ad network as seen in the following prototype/jsonp example.
ajax/jsonp example:
jsonp example: http://super.kitnmedia.com/publisher_api/adk_demo/prototype_ad_demo
implementation docs: http://cdn.superrewards-offers.com/docs/adk_overlay_api.html#igo_in...
source code: http://cdn.superrewards-offers.com/js/tools/interstitial/adk.inters...
This example relies on Dan Dean's jsonp implementation as described in the implementation docs.

@jwestbrook
Copy link
Collaborator Author

Alexander Vassbotn Røyne
February 3rd, 2011 @ 09:07 AM

What is the status on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants