I can not run JavaScript file in ajax Call
Hi Dears.
my code is like this :
Html Code :
<html>
<head>
<script src="jquery.js"></script>
<script>
function showHint(str)
{
if (str.length==0)
{
document.getElementById("usa").innerHTML="";
return;
}
var xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("usa").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","a.php" ,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="usa">
<img src="image/d2.jpg" onmouseover="omid(this)" />
</div>
</body>
</html>
and PHP code is :
<html>
<head>
<script src="jquery.js"></script>
</head>
<body>
<?php
echo "<h1 id='usa'>Salam Omid php</h1>";
echo '<script>
$("#usa").click(function(){
$.getScript("alert.js");
});
</script>';
?>
</body>
</html>
JS file:
when I run a.php the alert.js will run but when I call a.php using ajax، the javascript file in php file will not run.
how can i run java script file that are in another files ?
thanks.