doudui1850 2014-04-08 22:38
浏览 17
已采纳

$ _REQUEST ['id']从一个由javascript调用到另一个php页面的php文件中的页面

I'm trying to get the value 3 from this link: index.php?subtopic=example&id=3 Normally I would use the $_REQUEST['id'] but I'm facing another situation here.

I got the example1.php:

<script type="text/javascript" src="js/chatbox.js"></script>
...
<div id="chat_box"></div>

And then the chatbox.js:

setInterval( function() {
$('#chat_box').load('chatbox.php');
} , 100 );

And finally the chatbox.php:

echo $_REQUEST['id'];

but I can't get the id value here :/ Please Help!!!

  • 写回答

2条回答 默认 最新

  • dongshengyin0147 2014-04-08 22:50
    关注

    Basically you want to parse the id out of the URL and send it to the chat - let's do this:

    <script type="text/javascript">
      function getID() {
        var tmp=location.href.split('?');
        if (tmp.length!=2) return -2;
        tmp=tmp[1].split('&');
        for (i=0;i<tmp.length;i++) {
          var param=tmp[i].split('=');
          if (param.length!=2) continue;
          if (param[0]!="id") continue;
          return parseInt(param[1]);
        }
        return -3;
      }
    
      var chaturl='chatbox.php?id='+getID();
    
    </script>
    <script type="text/javascript" src="js/chatbox.js"></script>
    ...
    <div id="chat_box"></div>
    

    ...

    setInterval( function() {
    $('#chat_box').load(chaturl);
    } , 100 );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到
  • ¥50 高维数据处理方法求指导