此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

查看:412
本文介绍了此PHP脚本在Internet Explorer和Microsoft Edge中不起作用,但适用于Chrome / Firefox / Safari / Opera的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP 5.6

I used PHP 5.6

我写了一个php脚本,它读取一个文本文件并从中选择一个随机行,然后每当按钮发送到html得到一个随机行点击。

I wrote a php script which reads in a text file and picks a random line from it, then sends to the html whenever the button "Get a random line" is clicked.

在Chrome / Firefox / Safari / Opera中,这种方法很好但在Internet Explorer和Microsoft边缘,输出始终相同。它仅适用于第一次,并且在第一次按钮点击后不会更改输出我的意思是,对于第二次和进一步的点击,输出必须更改。

In Chrome/Firefox/Safari/Opera, this works fine but in Internet explorer and Microsoft edge, the output is always the same. It works only for the first time and doesn't change output after the first button click I mean, for the second and further clicks, the output has to change.

是有什么我必须专门为Internet Explorer和Microsoft Edge处理才能完成这项工作吗?

Is there something that I have to handle specially for Internet Explorer and Microsoft Edge to get this done ?

我尝试使用

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

之前和之后

 echo $randomLine; //In the php script

但这些没有帮助。

有人可以让我知道出了什么问题吗?谢谢.. !!

Can some one let me know what's going wrong ? Thanks..!!

更新1:

通过javascript按钮点击事件发出请求:

The request is made with button click event through 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中的最后一行如下:

and the final line in php is like:

echo $selectedRandomLine;


推荐答案

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

xmlHttprequest GET function can only transmit ASCII characters (Internet Explorer)

使用POST代替,这通常可以解决问题。

Use POST instead, this typically can fix the issue.

这篇关于此PHP脚本在Internet Explorer和Microsoft Edge中不起作用,但适用于Chrome / Firefox / Safari / Opera的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆