469,915 Members | 2,697 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,915 developers. It's quick & easy.

xmlHTTPRequest problem

Ive been playing around with xmlHTTPRequest and was wondering if i was
programming a part of my code wrong.

what i want to do is have the browser access another part of my site
using xmlhttprequest.

however, when i use xmlhttp.open("POST",
'http://xml.mysite.com/test.php')
it fails, but if i use xmlhttp.open("POST",
'http://www.mysite.com/test.php') it works. Is access to another url
restricted in xmlhttp?

thanks in advance.

Sep 12 '05 #1
4 1873
"David Wang" <da******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Ive been playing around with xmlHTTPRequest and was wondering if i was
programming a part of my code wrong.

what i want to do is have the browser access another part of my site
using xmlhttprequest.

however, when i use xmlhttp.open("POST",
'http://xml.mysite.com/test.php')
it fails, but if i use xmlhttp.open("POST",
'http://www.mysite.com/test.php') it works. Is access to another url
restricted in xmlhttp?


Yes!

Cross-domain access is restricted in JavaScript.
You *might* be able to step out of the sandbox by signing your script,
but I have never tested that myself. (I do it quite often with
signed Java Applets, thou...).

--
Dag.
Sep 12 '05 #2
"Dag Sunde" <me@dagsunde.com> wrote in message
news:jl*******************@juliett.dax.net...
"David Wang" <da******@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Ive been playing around with xmlHTTPRequest and was wondering if i was
programming a part of my code wrong.

what i want to do is have the browser access another part of my site
using xmlhttprequest.

however, when i use xmlhttp.open("POST",
'http://xml.mysite.com/test.php')
it fails, but if i use xmlhttp.open("POST",
'http://www.mysite.com/test.php') it works. Is access to another url
restricted in xmlhttp?


Yes!

Cross-domain access is restricted in JavaScript.
You *might* be able to step out of the sandbox by signing your script,
but I have never tested that myself. (I do it quite often with
signed Java Applets, thou...).


Forgot...

You can make a proxy script on 'http://www.mysite.com/test.php', that
calls 'http://xml.mysite.com/test.php' on the server side and returns
the result.

--
Dag.
Sep 12 '05 #3


David Wang wrote:
Ive been playing around with xmlHTTPRequest and was wondering if i was
programming a part of my code wrong.

what i want to do is have the browser access another part of my site
using xmlhttprequest.

however, when i use xmlhttp.open("POST",
'http://xml.mysite.com/test.php')
it fails, but if i use xmlhttp.open("POST",
'http://www.mysite.com/test.php') it works. Is access to another url
restricted in xmlhttp?


Yes, general with client-side scripting there are restrictions falling
under the "same origin policy" although that term has had a meaning
before XMLHttpRequest existed.

As for your particular problem in theory it could help to set
document.domain = 'mysite.com';
before you try your request as in your special case you do not want to
access a completely different domain but a subdomain.
I say in theory as that approach with setting document.domain was
introduced for cross frame scripting and I am not sure whether it
applies to XMLHttpRequest implementations as well.
You could try with your domain/sub-domains and report back whether that
improves things.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Sep 12 '05 #4
it looks as if modifying document.domain DOES NOT work. i ended up
just leaving the script in another directory. =(

Sep 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Chris Smith | last post: by
2 posts views Thread by Dominic Myers | last post: by
10 posts views Thread by Matt Kruse | last post: by
13 posts views Thread by TLaufenberg | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.