admin管理员组文章数量:1315258
Is it possible onclick to create session variable with javascript or jquery then use this variable with php ?
For example someone click link at the bottom
<div id="list"><a onclick = "" href="javascript:void(0);">+</a></div>
there will be created variable like number=1;
then I should call it in php like :
<?php $_SESSION["number"]; ?>
Is it possible onclick to create session variable with javascript or jquery then use this variable with php ?
For example someone click link at the bottom
<div id="list"><a onclick = "" href="javascript:void(0);">+</a></div>
there will be created variable like number=1;
then I should call it in php like :
<?php $_SESSION["number"]; ?>
Share
Improve this question
edited Nov 10, 2011 at 21:34
BerkErarslan
asked Nov 10, 2011 at 20:07
BerkErarslanBerkErarslan
691 gold badge1 silver badge9 bronze badges
1
- Session variables are stored server-side to uniquely identify the client. JavaScript only runs client-side anyway, so generating a session variable with it would be meaningless. – Blazemonger Commented Nov 10, 2011 at 20:09
2 Answers
Reset to default 3In order to pass a variable from JavaScript to PHP you have to make an ajax call. The easiest way is to use Jquery for that:
<script type="text/javascript">
function submitinfo(){
$.ajax({
type: "POST",
url: "yourfile.php",
data: "values=" + $("#button1");
});
}
</script>
Also add a function to a button or something...
<input type="button" id="button1" value="<?php print $values;>" onclick="submitinfo();"/>
Then in yourfile.php you simply get those values from $_POST['values'] and use wherever you want.
As others have pointed out you should not be creating session parameters with JavaScript, however if you need to get something from the client side to your server side, Ajax calls is the way to do it.
Sessions are maintained server side, it is not remended to create sessions client side, if it is very much necessary, you can call a server side script from client using any asynchronous libraries and have the server side code create session for you...
本文标签: phpuse onclick to create session variable with jquery or javascriptStack Overflow
版权声明:本文标题:php - use onclick to create session variable with jquery or javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741979605a2408316.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论