Ajax remote request

Discussion in 'JavaScript' started by geforce, Jun 25, 2008.

  1. #1
    This has been puzzling me all day.

    I have a site called TheClanIndex and I am wanting to release ventrilo monitors for my members. Now I have the following code for users to put on their website:

    
    <script type="text/javascript">
    <!-- Ventrilo Monitor from TheClanIndex.com
    tci_ventip = '85.236.100.69';
    tci_ventport = '11084';
    tci_ventheight = 300;
    tci_ventwidth = 160;
    tci_ventbgcolor = '333333';
    tci_ventfontcolor = 'ffcc00';
    // Ventrilo Monitor from TheClanIndex.com -->
    </script>
    <script type="text/javascript" src="http://www.theclanindex.com/vent/display.js"></script>
    
    HTML:
    So I am linking them to the .js file on my server. The JS file sends an AJAX request to http://www.theclanindex.com/vent/display.php which relays the server information back. This only works if I run the script here: http://www.theclanindex.com/vent/test.php But not if it is run from another URL.

    Does anybody know what could be causing this?
     
    geforce, Jun 25, 2008 IP
  2. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The problem is lied in your page url:

    xhr.open('GET', 'display.php?port=' + tci_ventport + '&bgcolor=' + tci_ventbgcolor + '&fontcolor=' + tci_ventfontcolor + '&ip=' + tci_ventip, true);

    It should be 'http://www.theclanindex.com/vent/display.php?port=' + tci_ventport + '&bgcolor=' + tci_ventbgcolor + '&fontcolor=' + tci_ventfontcolor + '&ip=' + tci_ventip

    If not then the page will requests the display.php in your client host, not in your host.
     
    koolman, Jun 25, 2008 IP
  3. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Well I tried that method, but when I do specify the full URL it doesn't display anything.
     
    geforce, Jun 25, 2008 IP
  4. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Please make sure browser cache is refreshed to load updated js file.
    Also check out other things. I am sure that you must use the full url.
     
    koolman, Jun 25, 2008 IP
  5. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #5
    There still seems to be some sort of permission problem I get a ready state 4, but permission denied when I look through Firebug. Is there any special permission I need to set on the display.php ??
     
    geforce, Jun 25, 2008 IP
  6. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
  7. koolman

    koolman Peon

    Messages:
    76
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    MJJ is right.
    On your display.php you need a php code:

    <?php header('Access-Control: allow <*>'); ?>
     
    koolman, Jun 25, 2008 IP
  8. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #8
    hmm, I gave that a shot, but still no luck, get this in firebug:

    Access to restricted URI denied"  code: "1012
    
    Line 0
    Code (markup):
    Do I need a certain CHMOD on the display.php ??
     
    geforce, Jun 25, 2008 IP
  9. MMJ

    MMJ Guest

    Messages:
    460
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Firefox 3 supports cross-domain ajax, firefox2 doesn't.
     
    MMJ, Jun 26, 2008 IP
  10. geforce

    geforce Active Member

    Messages:
    173
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #10
    Sorted it without AJAX, thanks for your input guys :)
     
    geforce, Jun 26, 2008 IP