且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将JavaScript变量传递给PHP会话变量

更新时间:2022-06-13 22:35:28

没有ajax?好的,

var img = new Image();
img.src = "script.php?myVal=" + encodeURIComponent(theValueToPass);

浏览器会尝试通过请求网址加载图片。显然这将是一个愚蠢的差事,但你的PHP脚本将被执行,并在php的 $ _ GET ['myVal']

The browser will try to load the image by requesting the url. Obviously it will be a fools errand, but your php script will get executed and the value available in php's $_GET['myVal']