调用PHP函数后HTML消失

这将显示按钮按下的结果。这个想法是它从文件中读取和写入,以便不同浏览器中的用户可以看到相同的结果。


我最初在访问 DOM 时遇到了一些问题,但后来发现在第一次按下按钮后,我的 php 脚本下面的所有内容都被擦除了This area doesn't get shown after button click


简单的解决方法是简单地将 DOM 元素向上移动,但是......我想知道......


为什么这个区域会被删除?就好像它被像 PHP 一样对待。


//Background Loop

function updateChat(){

            var file = 'word.txt?v=' + Date.now() ;

            var rawFile = new XMLHttpRequest();

            rawFile.open("GET", file, false);

            rawFile.onreadystatechange = function ()

            {

                if(rawFile.readyState === 4)

                {

                    if(rawFile.status === 200 || rawFile.status == 0)

                    {

                        var allText = rawFile.responseText;

                        console.log(allText);

                        document.getElementById("shownword").innerHTML = allText;

                    }

                }

            }

            rawFile.send(null);

    setTimeout(updateChat, 500);

}

<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">


    <title>Random Word Generator</title>


    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

    <script type="text/javascript"></script>

    <script language="javascript" src="update.js" type="text/javascript"></script>

</head>

<body onload="updateChat();">


<p id=shownword></p>


    <form action="" method="post">

    <input type="submit" name="word"

                class="button" value="Button1" id="button1"/> 

          

        <input type="submit" name="word"

                class="button" value="Button2" id="button2"/> 

    </form>

    


翻过高山走不出你
浏览 145回答 1
1回答

RISEBY

只需删除“返回;”if(isset($_POST['word'])) {&nbsp; postword();&nbsp; // return;}
打开App,查看更多内容
随时随地看视频慕课网APP