dtfbj24048 2013-05-30 12:34
浏览 94
已采纳

在通过jQuery加载的PHP中使用全局变量

I am using a jquery function to call a getdata.php file like this -

       $("#tasks").load("getdata.php?choice=" + $("#projects").val()); 

The getdata.php echoes back results dynamically to the callee.

<?php   //getdata.php                       
    global $user_id; //<--These variables are defined in the callee file
    global $con;
    $choice=$_GET['choice'];
    $query="SELECT task_id,title from tasks where user_id=$user_id AND proj_id=$choice";
    $result=mysqli_query($con,$query) or die(mysqli_error($con));
    if((mysqli_num_rows($res))!=0)
    {
        while (list($task_id, $title) = mysqli_fetch_row($result))
          {
           echo "<option value=$task_id>$title</option>";   
      }
     }
     else
     {
        echo "<option>No current Tasks</option>";
     } ?>

Is there any way by which I can access the variables in the callee file from here. I tried using global as would normally be the case with included files but that's not working here.

  • 写回答

2条回答 默认 最新

  • dongtang6718 2013-05-30 12:41
    关注

    You may consider using $_SESSION variables to set variables that are available to both your callee file and getdata.php.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂