As bergi said, the request is asynchronous. This means x returns immediately, and xmlHttp.onreadystatechange is called later. If you need to do something with the response from within y, pass it as a callback so x can call it when the time is right:
function x( callback )
{
if( pseudocode: request is ok )
{
callback( response );
}
}
function y()
{
x( url, function( response )
{
// do something with the response.
} );
}
UPDATE
xmlHttp.onreadystatechange is called with readyState 1, 2, and 3 before 4.
if( state === 4 )
{
if( statuscode === 200 )
{
// success
}
else
{
// failure
}
}
/*else
{
ignore states 1, 2 and 3
}*/