It seems that the JavaScript function to be executed after an AJAX response should be consistent for everyone, with the exception of a variable. In this case, it would be best to include the JavaScript function in your scripts file that is loaded normally, and have the AJAX response return the necessary variable (such as the user ID) to call the function as needed instead of injecting a new function each time.
If the AJAX response returns HTML, you can directly insert it into the DOM on a successful request.
I suggest always returning JSON even if the response is HTML. The JSON response could look like this:
{"responseType":"HTML", "varID":null, "payload":"<div>some html</div>"}
If the response is type JS, then the varID could have the variable and the payload could be null. This is just one example, but you could implement something similar to standardize the response while handling both scenarios.