We help IT Professionals succeed at work.

JSON : Cross Domain Scripting for XMLHTTPRequest

2,426 Views
Last Modified: 2012-06-27
Hi Experts,

I'm trying to get past the limitation of cross browser scripting using XMLHTTPRequest.

I've tried AJAX but nothing...but apparently JSON is able to do this, but I don't know how to even start.

Thing is I need to do a POST.

Could anyone help please?
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Here's the JSMX library if you're interested:
http://lalabird.com/

Many folks enjoy the prototype library, which is a bit more heavy, but popular:
http://www.prototypejs.org/
b0lsc0ttIT Manager
CERTIFIED EXPERT

Commented:
samrose,

Most current browsers will not allow this.   Firefox 3 is starting to work on methods to allow this securely but is more of an exception than a real method that can be used commonly.  There is no way that is commonly supported cross browsers.

For info on the way Firefox is starting to allow this (more as a draft and try to see how it will be accepted) look at:

http://ajaxian.com/archives/cross-site-xmlhttprequest-in-firefox-3
http://developer.mozilla.org/en/docs/Cross-Site_XMLHttpRequest

The idea is it would provide the server a way to say this can be done, for specific files.

The way the effect you want works now is using external JS files.  A remote domain will provide an external script file (a JS file) the other sites can use.  A script tag is included in their HTML source with the src attribute's value as this JS file.  This is a way that browsers will let cross domain scripting happen.  Of course the script is limited to what the external JS file does and you can't change that but it does allow access to the other site's "content", just very limited.

Let me know if you have any questions or need more information.  I hope this helps.

b0lsc0tt
b0lsc0ttIT Manager
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
samrose,

I read the question "...trying to get past the cross-browser limitation..." and your question title says "Cross Domain..."

b0Isc0tt is giving you the correct information regarding cross-domain, since Javascript has a same-origin policy and requires a proxy script to get around that.

Could you clarify your question -- do you mean cross browser - like differences in your Ajax calls -- or cross-domain as b0Isc0tt addresses?  If you need help cross-domain I'll bow out -- b0Isc0tt is awesome & very knowledgeable.  But if you're asking about using different browsers to get around the XMLHttpRequest differences -- then the function I gave should help out.

Either way we're glad to help out.
b0lsc0ttIT Manager
CERTIFIED EXPERT

Commented:
rowejd,
Good catch!  I had missed the difference.  Some clarification is needed.  It looks like either way he is off to a good start. :)
bol

Author

Commented:
Hi all,

Thanks so far for your comments.

I'm trying to basically use Javascript to post XML I.E for a RPC.

this is what I have tried...

<script type="text/javascript">
if (xmlhttp) {
 document.write('<p class="example"><a href="#" onclick="example3();return false;">Open the mac.</a></p>')
}
function example3() {
 xmlhttp.open("POST", "http://192.168.254.110:8080",true);
 xmlhttp.send("<?xml version=\"1.0\"?><methodCall><methodName>DBWindowFind</methodName><params><param><value><struct><member><name>request</name><value><string>name == 'Marshall Peter'</string></value></member><member><name>table</name><value><string>Study</string></value></member><member><name>execute</name><value><string>Open</string></value></member></struct></value></param></params></methodCall>");
}
</script>


If I add the website to IE's Intranet Zones it then works, but not if it doesn't.
Problem is getting this to work in Firefox.

It is cross domain, as I'm trying to from my website www.????.com run this script that will send the XML to the local 192.168.254.110:8080. But it also then allows someone else in another country say not in my own network, to run this so that it will work on their local 192.168.254.110:8080 (an osirix webserver for DICOM images if any one is interested.)



Is that enough info?
b0lsc0ttIT Manager
CERTIFIED EXPERT

Commented:
What version of IE?  If IE 6 I believe you will have a problem with IE 7, which did increase security in this area.
For Firefox you can try the solution recommended at http://kb.mozillazine.org/Links_to_local_pages_don%27t_work .  That will only work in a specific situation.  I don't know if this case will fall under that or not but it is definitely close and worth a try.  Like the IE "fix" you mentioned of adding the domain to the Intranet zone list this one would have to be done by the browser user.  The web developer can't do it.
My main doubt that the page above will provide a solution is that is for links on a page.  You want this for the XMLHTTPRequest object.
Let me know if you have a question about the page or what I have said here.
bol
b0lsc0ttIT Manager
CERTIFIED EXPERT

Commented:
I'm glad I could help.  Thanks for the grade, the points and the fun question.
bol

Author

Commented:
Thanks again b0lsc0tt :-)

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.