weixin_33694620 2016-02-01 20:21 采纳率: 0%
浏览 18

javascript响应为空

I am doing a response to php script.

<script >
function showHint(str) {
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function() {
            document.getElementById("result").innerHTML = xmlhttp.responseText;
    };
    xmlhttp.open("GET", "gethint.php?q=" + str, true);
    xmlhttp.send();
} </script>

And after i call showHint(str), i do:

var result = document.getElementById("result");

And it's always null. But this works fine and gives a right text:

<p><span id = "result"></span></p>

What i am doing wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?