اجرا نشدن کدهای JavaScript در درخواستهای Ajax
با عرض سلام و خسته نباشید به همه دوستان
من یه کد ای جکس نوشتم و تو صفحه خروجی کد alert() قرار دادم ولی نمایش نمی ده باید چه کار کنم؟؟؟؟
سورس فایل ها رو هم قرار می دم تا ببینید.
فایل index.php
[PHP]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax Web</title>
<script>
function GetXmlHttpObject(){
var xmlHttp = null;
try{
xmlHttp = new XMLHttpRequest();
}
catch(e){
try{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
xmlHttp = GetXmlHttpObject();
xmlhttp = GetXmlHttpObject();
function index(page){
var file = 'pages.php?page=';
xmlhttp.open('GET', file + page, true);
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
document.getElementById('index').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
</script>
</head>
<body id="index">
<script>index('test');</script>
</body>
</html>
[/PHP]
فایل pages.php
[PHP]
<?PHP
include($_GET['page'] .'.php');
?>
[/PHP]
فایل test.php
[PHP]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<script>alert("خوش آمدید.");</script>
</body>
</html>
[/PHP]
باتشکر