I have a home.php page that has a button to invoke an ajax call to replace the contents of an element
$(document).ready(function() {
$("#button").click(function() {
$ajax(...).done(function(response) { $("#home-cabinet").html(response) });
});
});
There are some HTML elements in the ajax response that I would also like to bind some event handlers. But the problem is I don’t know the content of response, so I cannot stick the jQuery element selector code inside .done().
It makes more sense if I can let the response set up the handlers itself. How can I do that?
Add to the response data
Just note that the DOM ready event doesn’t fire on ajax requests, so make sure the
<script>is written after the element.You should know what you’re going to get, it’s your domain you’re requesting… anyway the above should work just fine.