Let's say I get a response to a request to load AJAX data using a combination of JavaScript and HTML, for example:
<script>window.alert('Hello World!');</script> <p>This is a paragraph. Lorem ipsum dolor sit amet...</p>
If I simply put this answer in a div or other container, the script will not be executed automatically. I know that this can be done using the eval() function (as indicated in the example below), but eval is evil, so how can I do it right? Note: I do not use jQuery.
The following is an example AJAX bootloader:
function Load(id,url){ var ajax=new XMLHttpRequest(); ajax.onreadystatechange=function(){ if(ajax.readyState!=4)return; var obj=document.getElementById(id); if(!obj)return; obj.innerHTML=ajax.responseText;
source share