Use Ajax and Php to generate and run a javascript

Use Ajax and Php to generate and run a javascript

The idea is that a php file generates a javascrip code when it is called via Ajax. Is this possible?
Of course I also need to make sure the loaded script is run. Any suggestions?
Thanks.

e.g.

$.ajax({
type: "GET",
url: "test.php",
data: "country=USA",
dataType: "script",
success: function(){





             alert( typeof data );
}
});


test.php

echo "<script type=\"text/javascript\">";
echo "data = \"".$_GET['country']."\"";
echo "</script>";