将JavaScript变量转换为php [英] Converting JavaScript variable to php

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

问题描述

是否有任何方法可以将javascript变量转换为php变量

is there any method by which i can convert javascript variables to php variables

推荐答案

大多数初学者尝试这样做?

将PHP变量分配给PHP变量没有任何意义。您可以将javascript变量的值传递给PHP脚本,您可以在其中将这些值转换为PHP变量。有不同的方法将值从客户端(浏览器)传递到PHP脚本
Most of the begginers try to do this?
It doesn''t make any sense assigning javascript variables to PHP variables. You can pass the values of javascript variables to a PHP script, where you can get those values into PHP variables. There are different ways of passing values from client (browser) to PHP script


你能解释一下你需要做什么吗?


谢谢。
Could you explain in what situation you would need to do this?

Thanks.



是否有任何方法可以将javascript变量转换为php变量
is there any method by which i can convert javascript variables to php variables



Javascript无法直接与PHP交互。

这是因为Javascript在客户端的浏览器(客户端)上运行,而PHP在服务器(服务器端)。

因此,在您的Javascript代码被浏览器读取之前,所有PHP代码都已经由服务器执行。


有两种方法让Javascript与PHP通信。

您必须刷新/重定向页面,通过POST或GET协议发送数据。

或者,你可以使用AJAX。


使用d时我会非常小心ata由Javascript发送。由于它是由客户端的浏览器生成的,因此可以在发送之前轻松操作。

确保在使用之前对其进行验证。

Javascript can not interact with PHP directly.
This is due to the fact that Javascript is run on the client''s browser (client-side) while PHP is executed on the server (server-side).
So, before your Javascript code is even read by the browser, all of the PHP code will already have been executed by the server.

There are two ways to have Javascript communicate with PHP.
Either you have to refresh/redirect the page, sending along the data via the POST or GET protocols.
Or, you can use AJAX.

I would still be very careful when using data sent by Javascript. As it is generated by the client''s browser, it can easily be manipulated before it is sent.
Make sure you validate it before you use it.


这篇关于将JavaScript变量转换为php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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