如何将JavaScript变量传递给php函数 [英] how to pass the JavaScript variable to the php function
问题描述
我正在用javaScript编写代码。因为我需要调用php函数。
I am writing a code in javaScript. in that I need to call the php function.
但问题是我必须将Javascript变量传递给php函数。
But the problem is again I have to pass the Javascript variable to the php function.
我的javascrpt如下,(这是正确的)
My javascrpt is as follows,(is this correct)
<script>
obj.value="0254"
if (obj2.value != -1)
{
var PLOptions= "<?php PLOptions(?>"+ obj.value +"<?php)?>"
}
</script>
这里PLOptions()是php方法,obj.value是javascript变量。
Here PLOptions() is the php method and obj.value is the javascript variable.
请让我知道,我怎么能做到这一点。
please let me know, how can I achive this.
推荐答案
你可以'那样做。 PHP在服务器端执行,Javascript客户端。这意味着,PHP代码在Javascript之前执行。
You can't do that. PHP is executed server-side, Javascript client-side. What that means is, the PHP code is executed before the Javascript.
但是,您可以使用AJAX从Javascript调用PHP函数。
However, you could use AJAX to call a PHP function from Javascript.
这篇关于如何将JavaScript变量传递给php函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!