I have never had to return javascript from an XHR request. At the time when I had to apply behavior to dynamically loaded content, I could always do this in my script by making a call.
Can someone provide real cases in the real world, just so I know when you really need need for this (not for convenience), or for some reason why in some cases it is better to return js along with other content, rather than creating this functionality in your callback?
The only scenario that comes to my mind is on a highly customizable site, if the site supports several languages, for example, and the functionality changes depending on the language, and ajax is used for dynamic content and, perhaps, in some languages ββcertain behavior should happen, in while in others a different, and more efficient return of js to script blocks should occur, rather than dumping all this logic into a callback.
source
share