weixin_33674437 2015-09-30 18:12 采纳率: 0%
浏览 14

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.

  • 写回答

2条回答 默认 最新

  • 笑故挽风 2015-09-30 18:13
    关注

    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' ];
    
    ?>
    
    评论

报告相同问题?