+ 2

Php variable in script

I am working on a web app. I am coming across situations where I need to access php variable in script and change its value. How can I accomplish this?

3rd Dec 2017, 5:32 AM
Arunkumar Palanisamy
Arunkumar Palanisamy - avatar
3 ответов
+ 8
You simply cannot do that. You can assign php value to javascript variable, but you cannot assign javascript value to php variable. understand the server side and client side first.
3rd Dec 2017, 5:55 AM
Berli 🇮🇩
Berli 🇮🇩 - avatar
+ 5
yeah you must create an api in php gabby is correct, directly, but by creating a form to post/get data to a php script which will give you access to the variables that you need it is possible and quite common I might add server side -> client side is a one way street, but by creating a second script (or a function in the first) you can achieve 2 way communication
3rd Dec 2017, 6:24 AM
Adam
Adam - avatar
+ 2
yes you cant change server side value from client side so simply call Ajax to set or change value
3rd Dec 2017, 6:02 AM
Pavan Kumar T S
Pavan Kumar T S - avatar