javascript变量进入php [英] javascript variable into php
问题描述
我有一个php函数,在这个函数中我有一个javascript,它从父窗口获取我的元素的值。我现在的问题是,如何将此值传递给php变量
I have a php function, in this function I have a javascript which get the value of my element from parent window. My problem now is, how can I pass this value into php variables
任何帮助都会非常感激。
Any help would greatly appreciated.
谢谢
Tirso
我试过这段代码,但我的价值总是1
I tried this code but I got value always 1
这是我的代码
function do_upload()
{
$categories = print '<script type="text/javascript">window.top.window.$("#categories").val();</script>';
}
我为$ categories获得的值总是1;
the value I've got for $categories is always 1;
推荐答案
PHP print( )语言结构总是返回1.
The PHP print() language construct always returns 1.
PHP在服务器端执行。 JavaScript在客户端执行。你不能直接混合它们。你能做的最好的事情就是让JavaScript对服务器上的PHP脚本进行AJAX调用。
PHP executes on the server side. JavaScript executes on the client side. You cannot mix them directly. The best you could do would be to have JavaScript make an AJAX call to a PHP script on the server.
这篇关于javascript变量进入php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!