Try to use $.get() method to get/send data :
$.get("action.php",{}, function(data){
//data here contain 1
$.get("data.php", {id: data}, function(id){
alert(id);
}
});
Just echo $test
since just the data printed in page will return as responce to the query request.
action.php :
Hope this helps.