Check screen width and then pass variable on php variable

I want to check the screen resolution of the user. Now the solution is to check the screen resolution with AJAX and then pass variable to a PHP page. I have tried this but it does not work.

var width = $(window).width();

$.ajax({
    url: "/the-php-page-i-want-to-show-with-output.php",
    data: {
        screenwidth: width
    } 
}).done(function() {
    $(this).addClass("done");
});

and the php page /the-php-page-i-want-to-show-with-output.php:

<?
    $width11 = $_REQUEST['screenwidth'];

    if ($width11 < 769)
    {
        echo '<div class="test">mobile</div>';
    }
    else 
    {
        echo '<div class="test">desktop</div>';
    }
?>

Where is the problem?


Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.