I'm attempting to access resourced from multiple servers using AJAX, and i'm encountering this issue:

XMLHttpRequest cannot load http://first.mydomain.com. Origin http://second.mydomain.com is not allowed by Access-Control-Allow-Origin.

Using the following code

    for ( i in domains )
    {
        var url = 'http://'+domains[i]+'/mgmt/json/queue_status.php';
        requests[i]=new request(url);
        break;
    }

    function request(url)
    {
        var queues = {};
        http_request = new XMLHttpRequest();
        http_request.open("GET", url, true, 'username', 'password');
        http_request.onreadystatechange = function () {
            var done = 4, ok = 200;
            if (http_request.readyState == done && http_request.status == ok) {
                queues = JSON.parse(http_request.responseText);
                var queuesDiv = document.getElementById('queues');
                print_queues(queues, queuesDiv);                
            }
        }
        http_request.send(null);
    }

I've added the next to response page being asked for.

header('Access-Control-Allow-Origin: *');

I've attempted clearly naming the requester too without results.

Thanks

PS: The above mentioned code I am certain ins't perfect but function fine when only attempting to demands the resource from the host server.

account information aren't permitted in mix origin demands.

Throws an INVALID_ACCESS_ERR exception if either user or password is passed as argument and also the origin of url doesn't match the XMLHttpRequest origin.

source: http://www.w3.org/TR/XMLHttpRequest2/#the-open-method

Just pass the password and username like a get variable rather.