xmlHTTPRequest problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Wang

    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("P OST",
    'http://xml.mysite.com/test.php')
    it fails, but if i use xmlhttp.open("P OST",
    'http://www.mysite.com/test.php') it works. Is access to another url
    restricted in xmlhttp?

    thanks in advance.

  • Dag Sunde

    #2
    Re: xmlHTTPRequest problem

    "David Wang" <dasn0wie@gmail .com> wrote in message
    news:1126496360 .820115.248190@ o13g2000cwo.goo glegroups.com.. .[color=blue]
    > 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("P OST",
    > 'http://xml.mysite.com/test.php')
    > it fails, but if i use xmlhttp.open("P OST",
    > 'http://www.mysite.com/test.php') it works. Is access to another url
    > restricted in xmlhttp?[/color]

    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.


    Comment

    • Dag Sunde

      #3
      Re: xmlHTTPRequest problem

      "Dag Sunde" <me@dagsunde.co m> wrote in message
      news:jlbVe.5489 $qE.1204278@jul iett.dax.net...[color=blue]
      > "David Wang" <dasn0wie@gmail .com> wrote in message
      > news:1126496360 .820115.248190@ o13g2000cwo.goo glegroups.com.. .[color=green]
      >> 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("P OST",
      >> 'http://xml.mysite.com/test.php')
      >> it fails, but if i use xmlhttp.open("P OST",
      >> 'http://www.mysite.com/test.php') it works. Is access to another url
      >> restricted in xmlhttp?[/color]
      >
      > 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...).[/color]

      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.


      Comment

      • Martin Honnen

        #4
        Re: xmlHTTPRequest problem



        David Wang wrote:
        [color=blue]
        > 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("P OST",
        > 'http://xml.mysite.com/test.php')
        > it fails, but if i use xmlhttp.open("P OST",
        > 'http://www.mysite.com/test.php') it works. Is access to another url
        > restricted in xmlhttp?[/color]

        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

        Comment

        • David Wang

          #5
          Re: xmlHTTPRequest problem

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

          Comment

          Working...