我正在尝试在Kinetic.js / Javascript中创建一个PHP会话变量。
stage.on('mousedown', function(evt) {
var shape = evt.targetNode;
if (shape) {
if (shape.getFill() == 'green') {
//$_SESSION['room_name'] = shape.getAttr('key');
window.location.href = 'create.php';
}
}
});
单击我的形状时,我希望会话变量存储'key'属性,这是一个字符串,然后转到'create.php'。
我该怎么做?
编辑:Cerbrus,我试过你的建议:stage.on('mousedown', function(evt) {
var shape = evt.targetNode;
if (shape) {
if (shape.getFill() == 'green') {
var img = new Image();
img.src = "script.php?roomName=" + encodeURIComponent('hello');
window.location.href = 'create.php';
}
}
});
用户被发送到'create.php',但当我尝试在'create.php'中打印时:
<?php
echo $_GET['roomName'];
?>
没有任何回应
答案 0 :(得分:1)
你必须在url中设置roomName参数,以便你的php脚本可以读取它。
window.location.href = 'create.php?roomName='+ encodeURIComponent('hello');
您可以执行相同的操作来发送ID。
window.location.href = 'create.php?roomName='+shape.getAttr('key');