AJAX ReadyState 4状态200,但responseText未定义

时间:2015-07-17 02:04:42

标签: javascript php ajax

我有一个htmlphp文件:

test.html

var req = new XMLHttpRequest();
req.onreadystatechange = function() {
    if (req.readyState==4 && req.status == 200) {
      var dat = req.reponseText;
      alert("Status text: " + req.statusText);
      alert("Response: " + dat);
    }
  }; 
req.open("GET", "info.php", true);
req.send();

info.php

<?php
echo "test";
?>

访问info.php按预期显示“test”,但AJAX请求中的responseText始终未定义。我在这里缺少什么?

1 个答案:

答案 0 :(得分:4)

TYPO TYPO TYPO

var dat = req.reponseText;
               ^^^