Ajax-未收到请求

I have a JavaScript function that I use to start a request. I need the GET parameter of this request, but trying to access it through PHP does not return anything. Any idea why? I call the JS function in the same PHP file through which I try to access it (index.php)

JavaScript:

function aufloesung() {
    var request = new XMLHttpRequest();
    request.open("GET", "index.php?screen=1", true);

    request.send();

}

PHP File:

<script> aufloesung(); </script>

...

echo $_GET["screen"]

But I don't get the parameter.

Its easy by using jQuery and slicing your index.php & ajaxphp files.

include jquery.js in your index.php:

<script src="//code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
    aufloesung();
</script>

app.js:

function aufloesung() {

    $.ajax({ 
        type: "get", 
        url: "ajax.php?screen=1", 
        success: function( data ) {

            alert( data );

        }
    });

}

ajax.php:

<?PHP

    echo $_GET[ 'screen' ];

?>

You are making two separate HTTP requests.

The first one made by typing a URL into the address bar of the browser doesn't include the query string parameter but is rendered in the page.

The second one, made by using the XMLHttpRequest object, does include the query string parameter, but you don't do anything with the response so you can't see it.

You could, for example:

function aufloesung() {
    var request = new XMLHttpRequest();
    request.open("GET", "index.php?screen=1", true);
    request.addEventListener("load", function (event) {
        document.body.appendChild(
            document.createTextNode(this.responseText)
        );
    });
    request.send();
}