TimYates
asked on
Workarounds for Cross Domain (localhost + other) AJAX calls?
I have a website where I am using DWR to call the server in an AJAX style, however I now have a requirement to show user related data alongside that stored on the server.
My initial thought was that I could run a Java application (embedding Jetty) on the user's machine, and then load JSON from it by using an XHR request using the localhost:8888 url.
However, I'm getting security exceptions on the XHR.open method...
I thought you were allowed to load stuff from localhost? I guess not, when the main page url isn't from there...
Does anyone have any ideas on how this can be done? I don't want to upload the user's data (as it's huge), and so far I have the following ideas -- just wondering if anyone had any experience and knew of a way of getting this to work?
1) Have the server running on localhost serve an html page which can be loaded into a hidden IFRAME on the main page. Then have this IFRAME load the data into a JSON object from localhost, and then pass this JSON object back to the parent window (sounds convoluted, and would be nice to know if it might work before I try it)
2) Do it the way I am doing it, but do it right ;-) (I accept that the way I'm doing it MIGHT work, and it's just I have given up too easily)
3) Forget about it... It can't be done... (I know this is always a possible solution to problems like this)
Anyway...hope someone who has walked this path before can help :-)
Cheers!
Tim
My initial thought was that I could run a Java application (embedding Jetty) on the user's machine, and then load JSON from it by using an XHR request using the localhost:8888 url.
However, I'm getting security exceptions on the XHR.open method...
I thought you were allowed to load stuff from localhost? I guess not, when the main page url isn't from there...
Does anyone have any ideas on how this can be done? I don't want to upload the user's data (as it's huge), and so far I have the following ideas -- just wondering if anyone had any experience and knew of a way of getting this to work?
1) Have the server running on localhost serve an html page which can be loaded into a hidden IFRAME on the main page. Then have this IFRAME load the data into a JSON object from localhost, and then pass this JSON object back to the parent window (sounds convoluted, and would be nice to know if it might work before I try it)
2) Do it the way I am doing it, but do it right ;-) (I accept that the way I'm doing it MIGHT work, and it's just I have given up too easily)
3) Forget about it... It can't be done... (I know this is always a possible solution to problems like this)
Anyway...hope someone who has walked this path before can help :-)
Cheers!
Tim
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>> That should allow the json to be immediately executed
Ooooh... I'll give it a go :-)
Ooooh... I'll give it a go :-)
ASKER
I see what you mean now... I thought you meant that the Javascript loaded from the localhost could make AJAX calls to the localhost server...
Did you mean that I could embed the JSON into a script served from the localhost, and use that as my object?
If so, is there any way to "unload" javascript...
I know I can dynamically load scripts by manipulating the DOM, but will this gradually cause memory to be eaten up?
Did you mean that I could embed the JSON into a script served from the localhost, and use that as my object?
If so, is there any way to "unload" javascript...
I know I can dynamically load scripts by manipulating the DOM, but will this gradually cause memory to be eaten up?
Yes, I meant to load the script from localhost and have IT set the javascript varables like google does with its external javascripts in your page
ASKER
Right... I have decided to do the rendering and hosting as gmaps tiles on the client's machine (rather than as the client hosting the polyline information), as I can just point google maps to grab the tiles from the localhost...
Shame about that...
But thanks for all the help :-)
Tim
Shame about that...
But thanks for all the help :-)
Tim
ASKER
Bah...
It was going to be a sweet solution... being able to show local user data overlayed on my custom google map
I guess I need to have a long hard rethink... :-(