为什么PHP没有收到我的AJAX请求字符串?

I am puzzled as to why PHP sees my request string as undefined.

 $_GET['ask'] 
in my php file produces this error -> Notice: Undefined index: ask.

But when I query the php file from the url bar in the browser like this

localhost/Websites/webProject/data.php?ask=myquery 

I have set the php file to echo my string and it does do exactly that but only when I query it from the browser URL bar.

But when running the AJAX code normally from the parent html/php file

 request.open("GET", "data.php?ask=myquery", true); 

The PHP file does not see the query string and thinks its undefined.

Why is this the case?

I have tried to use

 $_REQUEST[]; 
but to no avail.

I am using pure javascript for the AJAX requests.

Here is the javascript

requestResponse();
function requestResponse()
{
  var READY_STATE_DONE = 4; /* request finished and response is ready */
  var SUCCESS          = 200; /* "OK" */

  setInterval(function(){
    var request = new XMLHttpRequest();
    request.onreadystatechange = function(){
      if(this.readyState == READY_STATE_DONE && this.status == SUCCESS)
      {
        var response = this.responseText;
        console.log(request.responseText);
        document.getElementById("test").innerHTML += "<br>" + response;
      }
    }
    request.open("GET", "data.php?ask=myquery", true);
    request.send();

  }, 3000)

}

Here is the PHP content

testRequest();
function testRequest()
{
  $reqString = $_REQUEST['ask'];
  include("dbCredentials.php");
  include("dbConnect.php");


  if($reqString == "myquery")
  {
    echo("<br />REQUEST IS: " . $reqString);
    echo("<br /> Your request is granted");
  }
}

DISCLOSURE: I have replaced the previous php file with data.php.

Try using Jquery Ajax request. this is mostly effective when you want to pass strings instead of serialized data

HTML:

    <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script type='text/javascript'>
    $(function(){
        $.ajax({
            type: 'post',
            url: 'data.php?ask=whut',
            success: function(response){
                alert(response);
            }
        });
    });
</script>

PHP Content:

echo $_GET['ask'];