【发布时间】:2014-11-15 07:09:19
【问题描述】:
索引页面从登录页面接收会话变量。我希望这个会话变量在用户没有任何操作的情况下发送到另一个 php 页面。使用 script.js 文件创建一个表并用数据填充。 script.js 文件有对 dbmanipulate.php 文件的 ajax 调用。 dbmanipulate.php 与数据库交互。现在无论如何将php会话变量从index.php发送到dbmanipulate.php 用户加载的唯一页面是 index.php,显示的是动态生成的表格。
编辑后我的 index.php 页面:
<?php
session_start();
$fname=$_SESSION['mail'];
?>
<!DOCTYPE HTML>
<html>
<title>Addressbook</title>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
function myFunction () {
$.ajax({
url:"DbManipulate.php",
type:"POST",
data:"<?php echo $fname ?>"
});
}
</script>
<link rel="stylesheet" type="text/css" href="crudstyle.css" />
</head>
<body onload="myFunction()" bg color="">
<div id="hidden_form_container" style="display:none;"></div>
<div id="mhead"><h2>Your Adressbook</h2></div>
<div id="note"> <span> your addressbook is connected to our servers :) </span></div>
<?php
echo $fname;
?>
<table id='demoajax' cellspacing="0">
</table>
<script type="text/javascript" src="script.js"></script>
</body>
</html>
【问题讨论】:
-
您需要在 DbManipulate1.php 中定义 session_start()。
-
会话启动将无法工作,因为 dbmanipulate 文件未通过索引访问。如果它们之间存在连接的流动,它会起作用
-
简单地说,使用隐藏的 iframe!
标签: javascript php jquery ajax session