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

亡梦爱人 提交于 2019-12-10 22:37:10

问题


I used PHP 5.6

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.

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.

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

I tried using

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

after and also before

 echo $randomLine; //In the php script

but these didn't help.

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

Update 1:

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();
}

and the final line in php is like:

echo $selectedRandomLine;

回答1:


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

Use POST instead, this typically can fix the issue.



来源:https://stackoverflow.com/questions/33847535/this-php-script-doesnt-work-in-internet-explorer-and-microsoft-edge-but-works-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!