duanji9378 2014-01-31 14:32
浏览 91
已采纳

在Kinetic.js / Javascript中创建PHP会话变量

I am trying to create a PHP session variable inside of Kinetic.js/Javascript.

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';
    }       
  }
});

When my shape is clicked, I want the session variable to store the 'key' attribute, which is a string, then go to 'create.php'.

How can I do this?

EDIT: Cerbrus, I tried you suggestion:

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';
    }       
  }
});

The user is sent to 'create.php', but when i tried to print it in 'create.php':

<?php
  echo $_GET['roomName'];
?> 

Nothing is echoed

  • 写回答

1条回答 默认 最新

  • dongyumiao5210 2014-01-31 15:01
    关注

    You have to set roomName parameter in url so it can be read by your php script.

    window.location.href = 'create.php?roomName='+ encodeURIComponent('hello');
    

    You can do the same to send the id.

    window.location.href = 'create.php?roomName='+shape.getAttr('key');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备