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条)

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao