There is one workaround that sounds more like a hack, and I agree that this is not the most elegant way to do this, but it works 100%:
Say your AJAX answer is similar to
<b>some html</b> <script>alert("and some javscript")
Please note that I specifically missed the closing tag. Then, in the script that loads the above, do the following:
$.ajax({ url: "path/to/return/the-above-js+html.php", success: function(newhtml){ newhtml += "<"; newhtml += "/script>"; $("head").append(newhtml); } });
Just donโt ask me why :-) This is one of those things that I came from as a result of desperate almost random trials and that fails.
I have no complete suggestions on how this works, but, interestingly, it will NOT work if you add the closing tag on one line.
In times like these, I feel that I am successfully dividing by zero.
Ash Dec 15 2018-12-12T00: 00Z
source share