The online racing simulator
JS loaded from Host1 AJAX'ing data from Host2 - possible?
Hello,

I'm playing about a bit with something that would be nice in an auto-updating webpage. It'd autoupdate via AJAX, polling data from a place on lfsworld every x seconds.

This works when I put both the JavaScript (the webpage) and the data source (a php script that outputs data) on lfsworld.
It doesn't work when I put the JavaScript on another host and then try to AJAX the data from lfsworld.

I know this is a security feature of JS, but would there be a way around it?

The idea is : the data source outputs race progress data from a host. You can make a nice race progress view with that (data includes host details and racer details like car, lapcount, but also all split and lap times).
As such, you can create a nice auto-updating host-info view on your webpage or so and it works for any licensed host. Since auto-updating is usually done with JS, but since you cannot use an 'outside source' to load from with AJAX, i wonder if the mentioned functionality can still be achieved?

EDIT - oh yeah, one way would be to use an intermediate url for AJAX, where AJAX polls a (php) script on the original host that in turn fetches the data from lfs world. But that requires additional work for people. Ideally people should only have to add a javascript include into their html and add a <div> with a certain id.

EDIT2 - oh yeah again, another way is that i could place a html page on lfsworld that people could put into an iframe on their own website. But this still isn't a total 'freedom' solution where you could make your own race progress view. In this case, using my html page on lfsworld would be the only option.
I believe most implementations only allow fetches from the domain where the script originated.

i.e. say a js script was included from lfsworld.net, the browser should allow requests to lfsworld.net and not to the domain that it included the file. No other way round it, unless you opt for the "proxy" approach.
You could always have a request.php file that the AJAX program would call to make the request. Takes away some of the coolness tho.
hehe you guys are just repeating what i already wrote

Anyway I've made up my mind. Thanks.
-
(ORION) DELETED by ORION : vic said exactly that actually.. doh :)
Quote from Victor :hehe you guys are just repeating what i already wrote

My excuse is that your 2 edits weren't there when I started writing
#6 - ORION
If i had to choose between an iframe and a single one line php to upload, I would definetely go for the php include
Quote from ORION :If i had to choose between an iframe and a single one line php to upload, I would definetely go for the php include

??? What about the third option? To request the javascript directly from LFSWorld?
Quote from the_angry_angel :??? What about the third option? To request the javascript directly from LFSWorld?

how would you go about that? Assuming you mean requesting the data directly from JS?

edit again - sorry
But i think i'm a bit confused now. You said request javascript directly from lfsworld - but what javascript do you mean there?
Would that not be stoped due to the XSS possibility's of it.
afaik there are only two options that will work.

1) Put an iframe into your html that loads a html page from lfsworld. This htmlpage contains the javascript code that AJAX's the data from a script on lfsworld and then displays the resulting data (into the iframe)

2) make your own javascript and put it into your own page. Then to request data from lfsworld, the javascript would query a script on your own host that in turn fetches the data from lfsworld (proxy)
If you put the following into a page on domaina.com;
<script type="javascript/text" src="domainb.com/myfile.js"></script>

you will find that you are able to make requests to domainb.com and rewrite the DOM on the page from domaina.com.

Make sense now? If you don't believe me, try it - it works.
hmm i thought i did try that .. but i'll give it a go later tonight. Gotta go out for a bit now.
yes i did test that before - it doesn't work. It DOES load JS from a remote site fine, but it does not allow the xmlHttp object to load anything from another domain than the _original_ domain the webpage is loaded from.

so,
<script type="javascript/text" src="domainb.com/myfile.js"></script>

does load the javascript from domainb.com, but any xmlHttp request must be made to domaina.com, otherwise it throws a permission denied error.
Try using the window.onload method within the js, rather than the body onload attribute - thats how I got something similar working a month or so ago.
nope, no worky.

also tried a setTimeout to trigger it all after 2 seconds (so not using the onload event), but made no difference.
Meh.. I'll dig through my svn repo backup tomorrow evening and see what I did
Is this not the same thing that Google is doing with Ad sense?

FGED GREDG RDFGDR GSFDG