Javascript undefined value from subdomain

Discussion in 'JavaScript' started by BlaZingPenguin, Dec 9, 2007.

  1. #1
    Hi, I'm fairly new to javascript and I am having an issue with variables when viewing from certain domains while using http.open
    this is images.domain.com/js.js, captcha.js works off it
    function createRequestObject() {
        var ro;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer"){
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            ro = new XMLHttpRequest();
        }
        return ro;
    }
    var http = createRequestObject();
    function handleResponse() {
        if(http.readyState == 4){
            var response = http.responseText;
            var update = new Array();
            if(response.indexOf('|' != -1)) {
                update = response.split('|');
                document.getElementById(update[0]).innerHTML = update[1];
            }
        }
    }
    Code (markup):
    this is captcha.domain.com/captcha.js, and I am trying to open domain/captcha/
    
    http.open('GET', "http://domain.com/captcha/",true);
    http.onreadystatechange = function()
    {
    if(http.readyState == 4 && http.status == 200)
    {
    response = http.responseText;
    captchaValues = response.split('||');
    texttoprint = captchaValues[0];
    document.getElementById("ahctpac").innerHTML = texttoprint;
    
    Code (markup):
    Now heres what happens when I view from these pages, which are all the same pages.
    http://register.domain.com/ undefined
    http://www.register.domain.com/ undefined
    http://domain.com/register/ works
    http://www.domain.com/register/ undefined


    Is there any reason why with different domains I should be getting undefined results? Is there also a term or phrase that I can look up as to what this might be a result of?

    Thanks

    *edit*

    just tested the undefined urls in ie and I am getting an error of Permission Denied
     
    BlaZingPenguin, Dec 9, 2007 IP
  2. BlaZingPenguin

    BlaZingPenguin Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thanks for the "JavaScript and AJAX prohibit direct cross-domain scripting." bit, sort of sucks. =[

    Fixed the error though, thanks.
     
    BlaZingPenguin, Dec 9, 2007 IP