Hello, i got a question, how do you pass a variable from jquery to php with a page refresh. When i click on a button from my menu i would like to pass a variable from jquery to php but because the page refreshes i cant catch it in php, anyone know how to catch it even when the page refreshes? tyvm
Use the query string like this:
<a href="somepage.php?myvar=somevalue">Click Me</a>
Now in the url you will have myvar query string var and you can get its value using php like this:
echo $_GET['myvar']; // somevalue
Make sure to sanitalize your query string variables.
First of all, you can avoid refreshing by using links like this:
<a href="javascript:void(0);" onclick="yourFucntionName();">Menu Title</a>
Secondly : Please note that if your link gets clicked then it will get you to a new page which is addressed in "href" attribute of the link, but your jQuery function is using onclick event to fetch another page (or the same page but with a variable). in fact you are making 2 requests but the browser will show you the one which is set by you href attribute,
if you want both refreshing and passing your variable you have to manipulate "href" attribute of your link instead of passing variable by jquery to a new page, like this:
<a href="someUrl" onclick="this.href=this.href+'&varName=varValue'">Menu Title</a>