F
F
Frank_Sidebottom2018-02-06 22:33:37
PHP
Frank_Sidebottom, 2018-02-06 22:33:37

How to pass variable value from js to php?

Goodnight! I click on the button and the value of the button's parent ID is passed to the variable. There are a lot of buttons and IDs, therefore, too. Now the task is to pass the values ​​of these IDs to the php file. Broke my head over this question. Tried through cookies, using the cookie plugin, but it does not see the variable and does not add cookies. I think it is necessary somehow through Ajax, but I am a complete zero in it. Help mi

$.cookie('cookie_nam', '$id');

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman Domoratskii, 2018-02-06
@domoratskii

You can use ajax, and accept $_POST or $_GET

E
entermix, 2018-02-06
@entermix

$.cookie('cookie_nam', '<?php echo $id; ?>');
And what does it mean

but it doesn't see the variable and doesn't add the cookie.
?
jquery.page2page.ru/index.php5/%D0%A0%D0%B0%D0%B1%...

N
Nurasyl Aldan, 2018-02-07
@nurasyl

From JS to PHP:
Through jQuery framework and plugin
$.cookie('var_name', 'value', { expires: 10, path: '/', domain: 'mydomain.ru', secure: false, });
echo $_COOKIE['var_name'];
From PHP to JS:
setcookie('var_name', 'value');
console.log($.cookie('var_name'));
Read more about PHP cookies here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question