I am having the ajax call, which gets the whole page from that page, I am getting the portion of the page(Which has the javascript). When I append that portion of the html page, javascript is not executed.
If I append the ajax response directly, the script is executed and working fine. My issue is, why javascript is not executed, when I try to append the portion of the page from ajax response ? I want to make it work. Any suggestions ?
Javascript function :
function showUsers(pageNumber) {
$.ajax({
url : '/ajax/users/show_users',
data : {
pageNumber : pageNumber == null ? 1 : pageNumber
},
type : 'get',
cache : false,
dataType: 'text',
success : function(response, textStatus, xhr) {
var resultData = '<div>' + response + '</div>';
var todo = $(resultData).find("#todo");
console.log(todo.text());
$('#users').html(todo);
}
});
};
show_users.html page :
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="/resources/js/jquery.js"></script>
</head>
<body>
<h1 id="kalees">My First Heading Kalees</h1>
<div id="todo">
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<script>
$(document).ready(function() {
alert("Hello world from ajax html page");
});
</script>
</div>
</body>
</html>