检查屏幕宽度,然后在php变量上传递变量

时间:2015-07-17 08:25:05

标签: javascript php jquery ajax

我想检查用户的屏幕分辨率。现在的解决方案是使用AJAX检查屏幕分辨率,然后将变量传递给PHP页面。我试过这个,但它不起作用。

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

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

和php页面/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>';
    }
?>

问题出在哪里?

0 个答案:

没有答案