繁体   English   中英

获取屏幕分辨率php和ajax(用于最小化SQL查询)

[英]Get screen resolution php and ajax (for minimize sql query)

我想用php获取屏幕分辨率,所以我使用了ajax,但是出了点问题...

İndex.php:

<html>
<head>
    <title>Minimize sql please</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script src = "script.js"></script>
</head>
<body>
<?php 
        $width = $_POST["width"];
        echo $width;
?>

scripts.js:

$(document).ready(function(){
    var width = window.innerWidth;
    $.ajax({
        type:'POST',
        url:'http://localhost/index.php',
        data:'width='+width,
        success:function(al){
            alert(al);
        }
    });
});

在此处输入图片说明

你做错了。 将您的PHP代码移动到一个新文件(例如,ajax.php)。 然后将您的script.js更改为:

$(document).ready(function(){
    var width = window.innerWidth;
    $.ajax({
        type:'POST',
        url:'http://localhost/ajax.php',
        data:'width='+width,
        success:function(al){
            alert(al);
        }
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM