0

I'm just blundering into AJAX, and I swear I'll actually learn my way around it real soon now, but all I need at the moment is to get the inner browser height, so I can ask the Google Maps Engine for a map of the appropriate height. (I'm actually making that request via the Google Maps plugin under Joomla. If I could somehow make that request on the client side, then I might not really have to mess with AJAX, but this would still be a good introductory exercize for me.)

I'm trying to grasp the basic AJAX setup by putting together a working minimal document incorporating code from the first answer at how to get screen width through php?. I realize that example is asking for a different attribute than I'll be asking for, but I'm just keeping the code as close to the original as possible.

I'm not totally clear on what code goes where, but apparently it is not this, at http://allbluesdance.com/testajax.php :

<!doctype html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Test Ajax</title>
</head>
<body>

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

    <script>
        var width = $(window).width();
        //This is ajax code which will send width to your php page in the screenWidth variable
        $.ajax({
            url: "http://allbluesdance.com/testajax.php", //this will be your php page 
            data : {screenwidth:width} 
        }).done(function() {
            $(this).addClass("done");
        });
    </script>

(Yeah, it's running)

    <!-- example.php code is here : -->
    <?php
        echo $width = $_REQUEST['screenwidth'];
    ?>

</body>
</html>

So unless I've made a dumb syntax error I could use a clue.

Thanks, Drew

Community
  • 1
  • 1

1 Answers1

0

I think you need to specify how AJAX gets the data, either through GET or POST. I Have been using this snippet and it works for me.

    // fire off the request

    var request = $.ajax({
        url: "/list/server.php",
        type: "POST",
        data: send_data
    });

    // callback handler that will be called on success
    request.done(function (response){
        // log a message to the console
        console.log(response);
    });
soarjay
  • 641
  • 4
  • 17