OK, since this is for AJAX, I assume you're loading the script by adding a new <script> tag to the DOM in the HTML <head>? I guess that you're also sending data to that script to fetch some results? e.g.
If so, then you could append a callback argument to this data which contains the name of the function you need to run once the script has loaded, e.g.
Your server side script would then put that call at the end of the code, e.g.
// ... do work and output JS code ...
// run callback function
$callback = $_GET['callback'];
if ($callback != '') echo "$callback()\