Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Workarounds for Cross Domain (localhost + other) AJAX calls?

Posted on 2007-07-31
7
Medium Priority
?
2,146 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:TimYates
  • 4
  • 3
7 Comments
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 19598787
Hidden iframe will have the same problem: cross frames/cross domain scripting.
UNLESS you use an HTML application where the parent page is saved with extension .HTA and the iframe has application="yes"
In that case IE will allow the user to open this page as an application and allow access across the frames.
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 2000 total points
ID: 19598795
Ahh...
you COULD try putting the localhost stuff as an external javascript

<script src="http://localhost..../..."></script>

That should allow the json to be immediately executed
0
 
LVL 35

Author Comment

by:TimYates
ID: 19598800
Right, so I'm basically stuck?

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... :-(
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 35

Author Comment

by:TimYates
ID: 19598803
>> That should allow the json to be immediately executed

Ooooh...  I'll give it a go :-)
0
 
LVL 35

Author Comment

by:TimYates
ID: 19598947
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?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 19599266
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
0
 
LVL 35

Author Comment

by:TimYates
ID: 19599845
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
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This article discusses how to create an extensible mechanism for linked drop downs.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month21 days, 1 hour left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question