此 PHP 脚本在 Internet Explorer 和 Microsoft Edge 中不起作用,但在 Chrome/Firefox/Safari/Opera 中起作用

This PHP script doesn't work in Internet explorer and Microsoft Edge but works in Chrome/Firefox/Safari/Opera

我用的是PHP5.6

我写了一个 php 脚本,它读取一个文本文件并从中随机选择一行,然后在单击 "Get a random line" 按钮时发送到 html。

在 Chrome/Firefox/Safari/Opera 中,这工作正常,但在 Internet Explorer 和 Microsoft Edge 中,输出始终相同。它仅适用于第一次,并且在第一次单击按钮后不会更改输出我的意思是,对于第二次和进一步的单击,输出必须更改。

为了完成这项工作,我必须为 Internet Explorer 和 Microsoft Edge 特别处理一些事情吗?

我尝试使用

//flush() 
//ob_flush()
//ob_end_flush()
//session_write_close()

之后和之前

 echo $randomLine; //In the php script

但这些都没有帮助。

谁能告诉我出了什么问题?谢谢..!!

更新 1:

通过javascript:

用按钮点击事件发出请求
function randomPathButtonClicked() 
{
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.onreadystatechange = function () {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            document.getElementById("randomPathId").textContent = xmlhttp.responseText;
        }
    };
    xmlhttp.open("GET", "serverSideRandomPathGenerator.php", true);
    xmlhttp.send();
}

php 中的最后一行是这样的:

echo $selectedRandomLine;

xmlHttprequest GET 函数只能传输 ASCII 字符 (Internet Explorer)

改用 POST,这通常可以解决问题。