我想检查用户的屏幕分辨率。现在的解决方案是使用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>';
}
?>
问题出在哪里?