xmlHTTPRequest problem

D

David Wang

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.
 
D

Dag Sunde

David Wang said:
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...).
 
M

Martin Honnen

David said:
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.
 
D

David Wang

it looks as if modifying document.domain DOES NOT work. i ended up
just leaving the script in another directory. =(
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top