An example can be executed using jQuery (javascript library).
If you call ajax request:
$.ajax({
url:"phpfile.php",
type:"post",
data: {id: 4},
async:true,
success: function(data) {
$("div").html(data);
},
error: function() {
alert("Error");
}
});
and in phpfile.php you echosome javascript code it can be executed:
<?php
echo "
<script>
jQuery(document).ready(function() {
$(\"#someDiv\").click(function() {
alert(\"#someDiv clicked\");
});
});
</script> ";
?>
source
share