On Tue, Feb 1, 2011 at 10:06 AM, Daniel Kinzler <daniel(a)brightbyte.de>wrote;wrote:
Hi all!
what's the best way to get around the same original policy to fetch data
from
the toolserver with a XMLHTTPRequest in a Wikipedia gadget? Is there a best
practice, a nice and easy, generally usable method? what would it take to
make one?
Easiest? Make an endpoint that returns data as JSONP (with a callback);
these can be loaded via <script> tags to get around same-origin policy, but
won't return good error information if a request fails. Best? Maybe output
appropriate CORS headers:
http://www.w3.org/TR/cors/
PS: while i'm at it, is there a wrapper function
for XMLHTTPRequest in the
standard MEdiaWiki JS? I don't want to re-invent a sucky wheel :)
jQuery is your friend. :) For the live sites I think you still have to
manually include it, but once 1.17 hits jQuery itself will be standard all
the time. You can use $.ajax or its simpler alias $.get.
[With the CORS headers, ISTR that IE 8 requires using a funny alternate XHR
class for cross-domain requests (XCrossDomainRequest or something cleverly
named -- this is Microsoft ;). I'm not sure offhand if jQuery can abstract
that bit for you.]
-- brion