使用 jQuery 发布屏幕宽度
使用此代码
var sw = window.screen.width;
$.post("http://www.example.com/track.php", {result: sw
}, "html");
和 $_SERVER['result'];在服务器中,我试图获取屏幕宽度,但它不起作用。是“结果”出了问题。我是 Javascript 和 jQuery 的新手...
Using this code
var sw = window.screen.width;
$.post("http://www.example.com/track.php", {result: sw
}, "html");
and $_SERVER['result']; in the server I'm trying to get the sreen width but it does not work. It is something wrong with the "result". I'm new in Javascript and jQuery...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
$_SERVER
包含服务器变量,即操作系统、引用 URL、服务器上各个文件夹的路径等内容。您要查找的是
$_POST
数组、$_GET
数组或$_REQUEST
数组。我可能在这里陈述了显而易见的事情,但它们包含的内容如下:$_POST
包含发布到脚本的所有变量的列表。$_GET
包含查询字符串中所有变量的列表(例如:someScript.php?x=1&y=2
)$_REQUEST
包含$_POST
、$_GET
和$_COOKIE
的合并(通常按该顺序)。我不建议使用它:您应该知道用于将变量放入脚本中的方法并专门使用该数组。对于您的情况,您需要查看
$_POST
数组。运行一次总是很方便:这将向您显示发布到该页面的所有内容。
$_SERVER
contains server variables, that is, things like the operating system, the referrer URL, paths to various folders on the server.What you're looking for instead is either the
$_POST
array, the$_GET
array, or the$_REQUEST
array. I might be stating the obvious here, but here's what they contain:$_POST
contains a list of all variables POSTed to the script.$_GET
contains a list of all variables in the query string (eg:someScript.php?x=1&y=2
)$_REQUEST
contains a merge of$_POST
,$_GET
and$_COOKIE
(usually in that order). I don't recommend using this: you should know the methods you're using to get variables into your script and use that array specifically.In your case, you need to take a look at the
$_POST
array. It's always handy to run this once:This will show you everything posted to that page.
jQuery $.post 函数向服务器发送一个 post 请求,这意味着要访问“result”的值,您需要从 $_POST 超全局中获取它。
尝试 $_POST['result'] 而不是 $_SERVER['result']。
这些描述可能会有所帮助(来源:http://www.nusphere.com/php/php_superglobals.htm ):
通过 HTTP POST 的脚本。这是
通常是一个带有方法的形式
邮政。
从 Web 服务器到 PHP 脚本
本身(不是您要查找的内容)
$_GET、$_POST 和 $_COOKIE(将
工作,但为什么要搜索 GET 和 COOKIE
当你知道该值在 POST 中时?)
The jQuery $.post function sends a post request to the server, which means to access the value of "result", you need to get it from the $_POST superglobal.
Try $_POST['result'] instead of $_SERVER['result'].
These descriptions may help (source: http://www.nusphere.com/php/php_superglobals.htm):
script via HTTP POST. This is
normally a form with a method of
POST.
to a PHP script from the Web server
itself (not what you're looking for)
$_GET, $_POST, and $_COOKIE (would
work, but why search GET and COOKIE
when you know the value is in POST?)
尝试做:
Try doing:
使用
$_REQUEST['结果']
正确的方法是使用
$_POST['result']
,正如其他人在这里建议的那样。Use
$_REQUEST['result']
The correct way is to use
$_POST['result']
, as suggested by others here.