解決済みの質問

IEでAjax

現在、以下のソースをもとにAjaxのテストをしているのですが
FireFoxだと正常に動作されますが、IE8だと無反応です。
もちろんJavaScriptは有効にしています。
この原因はどこにあるのでしょうか?


■test.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitiona...">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>テスト</title>
<script type="text/javascript">
<!--
var ajax = new XMLHttpRequest();

function makeTable(keyword) {
 ajax.onload = function() {
  document.getElementById('layerTable').innerHTML = ajax.responseText;
 }

 ajax.open('GET', 'sample.php?keyword=' + keyword, true);
 ajax.send(null);
}
</script>
</head>

<body>
<h1>Ajaxのテスト</h1>
<form id="formMain" name="formMain" method="post" action="">
<p>キーワードを入力して、表示するボタンをクリックしてください。</p>
<p>
<input type="text" name="keyword" size="35"> <input name="buttonMake" type="button" id="buttonMake" value="表示する" onClick="makeTable(this.form.keyword.value)" />
</p>
</form>
<div id="layerTable">ここに応答が表示されます</div>
</body>
</html>


■sample.php
<?php
$keyword = $_GET['keyword'];
$doc = "<b>Ajaxのテストです</b><br />";
$doc .= "キーワードは{$keyword}";
print($doc);
?>

投稿日時 - 2011-05-08 08:51:47

QNo.6722228

困ってます

質問者が選んだベストアンサー

IE8 は onload 未対応だったと思います。
onreadystatechange にしてみたらどうでしょうか?
http://www.w3.org/TR/XMLHttpRequest2/#dispatch-readystatechange-event

投稿日時 - 2011-05-08 21:55:39

お礼

ありがとうございます。
早速試してみます。

投稿日時 - 2011-05-09 08:54:22

ANo.1

2人が「このQ&Aが役に立った」と投票しています

あわせてチェックしたい
  • \'xjis.nls\' ...
  • window.openが上手く行きません ...
  • セキュリティについて ...
PR

OKWaveのオススメ

教えて弁護士さん!

お金の悩みQ&A特集はこちら