have you checked out Request.JSONP?

http://mootools.net/docs/more/Request/Request.JSONP

it provides an onComplete event listener.

On Mon, Apr 27, 2009 at 5:20 PM, pradador <prada...@gmail.com> wrote:

>
> I wanted to add a couple of widgets to a homepage I'm designing.
> There's plenty of PHP libraries out there but this causes the widgets
> to load before the page is displayed. If for example, Twitter is under
> heavy load, this can affect my page load times greatly.
>
> Since I wanted to the plugins to load after the basic page is
> rendered, I figured I'd turn to MooTools to render the widgets on load
> or domready events. However, accessing the API data via JS is giving
> me trouble. Cross-domain XHR requests are out of the question of
> course. iFrames would be simple, but they are not much fun to deal
> with. So instead, it seems the common method is to create a script
> element which points to the request URL. The APIs then return JSON
> data wrapped in a callback function for you to handle.
>
> For example, using the Twitter API:
> 1. I create a script element and set the src to:
> http://twitter.com/help/test.json?callback=jsonp
> 2. I am returned this: jsonp("ok");
> 3. In my code, I have the global function jsonp(data) which handles
> the response accordingly. In this case I might just want to do alert
> (data);
>
> It's a decent solution, but I'd like to be able to do more. The script
> element method resigns me to use the data either within the context of
> the callback function or within the global scope. It's not very OOP. I
> want to be able to call something like "myAPIObject.getUserDetails()"
> and get the raw data back which I can process as I see fit.
>
> My current approach is to create a companion PHP script as a proxy. It
> simply takes the URL as a parameter and it returns the response from
> the API using a cURL call. From the MooTools side, I simply do an XHR
> request to the script and then handle the string response using eval
> ().
>
> Any thoughts or suggestions on the matter? Hopefully I'm not just
> missing some obvious method of doing this lol.

Reply via email to