How to print JavaScript with PHP

前端 未结 3 1628
半阙折子戏
半阙折子戏 2021-01-25 23:44

I need to pass some JS variable to PHP and am having some trouble.

I have tried the following:

$product_id = \"

        
3条回答
  •  终归单人心
    2021-01-26 00:24

    JavaScript runs on the client side while PHP runs on the server. They execute at completely different times in the page lifecycle, so they cannot communicate in the manner you have used.

    Instead you could to use AJAX to send a value in JS to a PHP page.

提交回复
热议问题