获取客户端分辨率传给服务器端php

做毕设时,碰到了这个问题。因为要在不影响用户浏览网页内容的情况下获取到并存入数据库中,需要用到异步ajax post给服务器端

客户端js

$(document).ready(function(){
    var Userinfo_url = "<?php echo site_url('Userinfo'); ?>";
    var h = window.screen.height;
    var w = window.screen.width;
    $.ajax({
	type : "POST",
	url : Userinfo_url,
	data : {"width" : w, "height" : h},
	success : function(){}
    });
});

在用户的DOM文档树加载完,开始post,Userinfo_url是要post的路径。

服务器端php

$userinfo=array(
    'screen_width'=>$_POST['width'],
    'screen_height'=>$_POST['height']
);

猜你喜欢

转载自blog.csdn.net/weixin_37618596/article/details/80315441