Answer the question
In order to leave comments, you need to log in
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
$.cookie('cookie_nam', '<?php echo $id; ?>');
And what does it mean
but it doesn't see the variable and doesn't add the cookie.?
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 questionAsk a Question
731 491 924 answers to any question