This PHP script doesn't work in Internet explo

2019-07-20 07:37发布

问题:

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.