私は最初のajaxの例をMAMPで動作させようとしています。私のajax.htmlは次のようになります:
<html>
<head>
<script src='ajax.js'></script>
</head>
<body onload = 'ajax()'>
<div id='test'></div>
</body>
</html>
私のajax.jsは次のようになります:
関数ajax() {{ >> var xmlhttp;
if(window.XMLHttpRequest) {// IE7 +、Firefox、Chrome、Opera、Safariのコード xmlhttp = new XMLHttpRequest(); } そうしないと {// IE6、IE5のコード
xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP"); } xmlhttp.open( "GET"、 "http:// localhost:8888 / ajax.php"、true); xmlhttp.send(); xmlhttp.onreadystatechange = function() {{ if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {{ document.getElementById( "test")。innerHTML = xmlhttp.responseText; } } }
私のajax.phpは次のようになります:
echo'hello world';
ファイアバグからの応答ヘッダーを検出しました:
応答ヘッダー
接続Keep- AliveContent-
Length11
Content-Type text / html
Date Mon、05 Nov 2012 18:57:46 GMT
Keep-Alive timeout = 5、max = 99
Server Apache / 2.2.22(Unix)mod_ssl / 2.2 .22 OpenSSL / 0.9.8r DAV / 2 PHP /5.4.4X-Pad
はブラウザのバグを回避し
ますX-Powered-ByPHP/ 5.4.4
しかし、応答テキストには何もありませんし、私のhtmlにも何も変更されていません。
誰か助けてくれませんか?
ありがとう!