php 无需页面刷新即可更新会话变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17963243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
update session variable without page refresh
提问by Karvin Mendis
I need to update the session variable on page 1, when click on a link in iframe (external page). session variable is successfully set when i click on iframe's link. the problem is i need to refresh the page 1 to update that session variable on page1.
单击 iframe(外部页面)中的链接时,我需要更新第 1 页上的会话变量。当我单击 iframe 的链接时,会话变量已成功设置。问题是我需要刷新第 1 页以更新第 1 页上的会话变量。
how to resolve this.any ajax , jquery help. THanks
如何解决 this.any ajax ,jquery 帮助。谢谢
回答by Bora
HTML a href
link:
HTMLa href
链接:
<a href="#" id="clickme">Update Session</a>
jQuery codes:
jQuery 代码:
You can send data with line of data: { varname: 'here we go'}
您可以使用以下行发送数据 data: { varname: 'here we go'}
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$("#clickme").click(function(e) {
e.preventDefault();
$.ajax({
type:'POST',
url:'update.php',
data: { varname: 'here we go'},
success:function(response){
alert(response);
}
});
});
</script>
update.php file:
update.php 文件:
You can get sent var with $_POST["varname"]
你可以得到发送 var $_POST["varname"]
<?php
$_SESSION["varname"] = $_POST["varname"];
echo $_SESSION["varname"];
?>