I've encountered a case when an ajax call would return new HTML that includes the script that needs to execute. The code looked like this:
$.ajax('/url', {
method: 'get',
success: function(response) {
document.getElementById("my-body").innerHTML = response;
}
});
In that code above, response
would contain the script that needs to be executed, but it would not execute. Changing the success
callback to the following fixed it:
$("#my-body").html(response);
I'm not sure why that was the case (obviously it has to do with the implementation of .html()
method). Perhaps someone could comment with an explanation