Set phps $_REQUEST['variable_name'] in JavaScript

后端 未结 4 674
轮回少年
轮回少年 2021-01-21 20:00

is it possible to store a variable through javascript so that I can read it in php using $_REQUEST[\'variable_name\'].

for eg. let\'s say i have

$adcat         


        
4条回答
  •  后悔当初
    2021-01-21 20:51

    It's less of a technical problem, more of how you structure your code and interaction between the PHP backend and in-page Javascript.

    To get the $category_id variable into Javascript, the typical approach is:

    category_id = $category_id;";
    

    To have your Javascript code send a catid back to a PHP page:

    $("#id").load("page.php?category_id="+category_id);
    

    This would ping it back to PHPs $_REQEUST[] array. But the question is why you need the variable available in Javascript first.

提交回复
热议问题