0

我在 php 中创建了一个井字游戏。我创建了以下代码来显示网格并将请求发送到 php-

<html>
<head>
<script type="text/javascript">
function showData(str)
{
    if(str==""){
        document.getElementById("showData").innerHTML="";
    }
    if(window.XMLHttpRequest){
        //code for IE7+, Firefox, Chreom, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else{
        //code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function(){
        if(xmlhttp.readyState==4 && xmlhttp.status==200){
            document.getElementById("showData").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","tttoe?move="+str,true);
    xmlhttp.send();
}
</script>
</head>
<body>
<center>
<div id="showData">
<table border="1" cellpadding="1" cellspacing="1">
    <tr>
        <td>&nbsp;<input type="button" class="button1" name="move" value="1" onClick="showData(this.value)" />&nbsp;</td>
        <td>&nbsp;<input type="button" class="button1" name="move" value="2" onClick="showData(this.value)" />&nbsp;</td>
        <td>&nbsp;<input type="button" class="button1" name="move" value="3" onClick="showData(this.value)" />&nbsp;</td>
    </tr>
    <tr>
        <td>&nbsp;<input type="button" class="button1" name="move" value="4" onClick="showData(this.value)" />&nbsp;</td>
        <td>&nbsp;<input type="button" class="button1" name="move" value="5" onClick="showData(this.value)" />&nbsp;</td>
        <td>&nbsp;<input type="button" class="button1" name="move" value="6" onClick="showData(this.value)" />&nbsp;</td>
    </tr>
    <tr>
        <td>&nbsp;<input type="button" class="button1" name="move" value="7" onClick="showData(this.value)" />&nbsp;</td>
        <td>&nbsp;<input type="button" class="button1" name="move" value="8" onClick="showData(this.value)" />&nbsp;</td>

        <td>&nbsp;<input type="button" class="button1" name="move" value="9" onClick="showData(this.value)" />&nbsp;</td>
    </tr>
</table>
</div>
</center>
</body>
</html>

有没有办法让我可以显示一个文本(处理中.....)直到请求完成?

4

1 回答 1

2

您可以在 html 和您的divid中添加:statusjs

document.getElementById('status').innerHTML = 'processing';

在您的功能开始时和

document.getElementById('status').innerHTML = 'whatever you want';

if(xmlhttp.readyState==4 && xmlhttp.status==200){
于 2012-08-15T12:13:41.860 回答