如何将JavaScript变量传递给php函数 [英] how to pass the JavaScript variable to the php function

查看:82
本文介绍了如何将JavaScript变量传递给php函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何将javascript函数数据转换为Php变量

我正在用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屋!

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