Using a javascript variable to set PHP variable [duplicate]

邮差的信 提交于 2020-01-10 05:55:07

问题


Possible Duplicate:
Get variable from PHP to JavaScript
Access a JavaScript variable from PHP

I currently have this line of code:

displaystatus('CALLER IS: '+inCallingNum);

which is being used to display a message on the page saying (e.g.) CALLER IS: 01234 567890.

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;

Thanks for any help

Edit:

This is where inCallingNum is set:

inCallingNum = inCallingNum.slice(inCallingNum.lastIndexOf(",")+1, inCallingNum.length);

Edit 2:

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.


回答1:


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.

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.




回答2:


Since JS is run after Apache processes the PHP page, this is not possible.




回答3:


you can try this,

<?php $user_number = inCallingNum ?>

where inCallingNum is your javascript variable.



来源:https://stackoverflow.com/questions/5948314/using-a-javascript-variable-to-set-php-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!