使用javascript变量设置PHP变量 [英] Using a javascript variable to set PHP variable
问题描述
我目前有这条线代码:
displaystatus('CALLER IS: '+inCallingNum);
用于在页面上显示消息(例如)CALLER IS:01234 567890。
which is being used to display a message on the page saying (e.g.) CALLER IS: 01234 567890.
我现在需要做的是在PHP变量$ user_number中设置inCallingNum变量的值。这可能吗?
What I need to do now is set the value of the inCallingNum variable in a PHP variable $user_number. Is this possible?
我试过这样的事情,但没有任何运气:
I tried something like this, but didnt have any luck with it:
<?php $user_number ?> = inCallingNum;
感谢您的帮助
编辑:
这是设置inCallingNum的地方:
This is where inCallingNum is set:
inCallingNum = inCallingNum.slice(inCallingNum.lastIndexOf(",")+1, inCallingNum.length);
编辑2:
我会试着解释一下我想要做的更清楚。我目前所拥有的是2页,显示所有信息的主页和查询数据库的第2页,并提取用户的个人资料。当jall变量inCallingNum发生变化时,我需要将其发送到user_data.php页面并更新信息以显示新人的个人资料。
I'll try to explain what I'm trying to do more clearly. What I have at the moment is 2 pages, the main page which displays all of the information and a 2nd page which queries the database and pulls out the user's profile. When the javascript variable inCallingNum changes, I need to send this to the user_data.php page and update the information to show the new person's profile.
推荐答案
Php是服务器端代码,javascript是客户端代码。无法按照您的要求进行操作,您必须通过调用服务器来设置 $ user_number
。
Php is server-side code, javascript is client-side code. It is not possibile to do what you're asking, you have to set $user_number
with a call to the server.
当您使用javascript时,您已经收到了服务器的响应,因此您正在处理服务器端操作的结果,您无法从结果中更改源。
When you are working with javascript you have already had the response from the server, so you are working with the result of the server-side actions, you cannot change the source from the result.
这篇关于使用javascript变量设置PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!