【问题标题】:This PHP script doesn't work in Internet explorer and Microsoft Edge but works in Chrome/Firefox/Safari/Opera此 PHP 脚本不适用于 Internet Explorer 和 Microsoft Edge,但适用于 Chrome/Firefox/Safari/Opera
【发布时间】:2016-02-24 04:07:16
【问题描述】:

我使用的是 PHP 5.6

我编写了一个 php 脚本,它读取一个文本文件并从中选择一个随机行,然后在单击“获取随机行”按钮时发送到 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;

【问题讨论】:

  • PHP 运行服务器端,独立于浏览器。请提供您的按钮代码。是 AJAX 请求还是整页刷新?
  • @clemens321 添加了代码。请检查。谢谢

标签: php internet-explorer microsoft-edge


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    • 2021-06-05
    • 2023-01-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-03
    相关资源
    最近更新 更多