+ 1
How to update data in php and js
I have a variable $ x = 5 in pxp, I want to give this value to js, how should I do that? And how to set php functions like vslue to atrebute onclick
1 ответ
+ 2
The first thing that should be known is that JS and PHP don’t usually run together.
PHP is run on the server’s computer, when you’re loading a webpage.
JS is run on the client’s computer, after a webpage has loaded.
If you wanted to pass a value from PHP to JS, there are a few options:
1. Use PHP’s echo to hardcode it directly into the JS code when the page is being loaded
2. Use AJAX in JS to make a request to the server, and the server can return a value. This can also be used for letting JS tell something to PHP.
If you don’t know about some of these concepts, Google should help (but then again, it might not).
Hope this helps you.