在同一页面上将jQuery变量传递给PHP? [英] Passing jQuery variable to PHP on the same page?

查看:61
本文介绍了在同一页面上将jQuery变量传递给PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是Stack Overflow上的一个常见问题,但是我找不到在同一文件中PHP代码位于JS脚本上方的情况.我猜在这种情况下,ajax POST/GET将无法完成工作?

I know this is a frequent question on Stack Overflow but I couldn't find scenario where the PHP code is just above JS script in the same file. I guess ajax POST/GET won't do the job in this case?

(...)
var ww = $(window).width();
   </script>

<?php $ww = [data here] ?>

推荐答案

必须使用POST/GET将JS变量发送到PHP,因为PHP是由服务器处理的,而JS是由客户处理.

You will have to use POST/GET to send a JS variable to PHP, because PHP is processed by the server and JS is processed by the client.

我知道这不是您想听到的.

I know this isn't what you want to hear.

这篇关于在同一页面上将jQuery变量传递给PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆