晚安!
我有一个页面“student_area.php”,它有10个链接(即10个主题),点击后,在新的浏览器选项卡中打开一个新的php页面。
student_area.php是注册用户的登录页面,它将用户的“exam_type”存储在p元素中。因此,元素'exam_type'在成功登录后设置,值可以是1到10。
因此,如果学生点击“数学”链接,它会在新窗口中打开math.php页面。
我在前端使用javascript,服务器端使用php。
在math.php中,我试图使用.load()函数从student_area.php中获取'exam_type'的值,但load()没有返回所需元素的值。
它返回所有静态元素,但不返回动态元素,例如exam_type。
任何人都可以指导我
问候
答案 0 :(得分:0)
您可以使用会话或Cookie。
<!-- first page -->
<?php
session_start();
$_SESSION['exam_type'] = '1';
?>
<!-- second page -->
<?php
session_start();
echo $_SESSION['exam_type']; // it will print 1
?>
看到它。 http://php.net/manual/en/session.examples.basic.php http://php.net/manual/en/session.examples.php
或javascript
function post_to_url(path, params, method) {
method = method || "post"; //default post method
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);
//input type hidden name(key) value(params[key]);
for(var key in params) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
form.appendChild(hiddenField);
}
document.body.appendChild(form);
form.submit();
}
并打电话给你。 post_to_url('math.php', {'exam_type':'1'});
在math.php中
$_POST['exam_type'] // 1