Hi All,
An experiment i'm doing requires requires a synchronous cross-domain
request, without using a proxy. I wondered if anyone had any ideas to
help me achieve this.
Below is what I have tried, including my conclusions/assumptions
(which i'll happily be corrected on if it solves my problem!):
The requirement not to use a proxy means I can't use the synchronous
mode of XMLHttpRequest, as it will not let me go cross-domain.
On-demand loading of javascript enables me to achieve the cross-domain
request by loading javascript of the form:
callback(data);
which on loading calls callback(), but it is not obvious how to make
this synchronous. I've also managed to get the same effect using a
hidden IFRAME, but again it relies on a callback. Is there a good way
to wrap/transform this in to a synchronous request?
The closest solution i've found which can probably solve it is the
narrative js (http://neilmix.com/narrativejs/doc/index.html), which
pre-processes javascript to turn a "yeild" function in to co-routines,
but this is getting a little scary/heavyweight!
Regardless of the actual implementation, the model i require is:
x = foo.bar();
where bar() returns a value based in part on the result of a cross-
domain request. i.e. the programmer doesn't care about the
implementation of bar(); it may be a standard method call, or may
include one or more cross-domain requests. The implementation details
must be hidden, hence at this level it appears as a normal blocking
call (i.e the solution is not "synchronous calls are evil, you should
be using asynchronous!").
Any ideas, pointers or suggestions would be very useful!
Thanks,
Simon