donglu6805 2016-06-03 03:34
浏览 45

$ _GET在if语句中随机取消设置

I'm sure there is a simple answer to this stupid problem but I have searched high and low and can not figure out why this wont work.

$tutorid = $_GET['userid'];

var_dump($tutorid);

//populate user tutoring subjects
if( isset($_POST['a'])) {
  $currentsubjects = get_current_user_subjects( $tutorid );
  unset($_POST['a']);
  echo json_encode($currentsubjects); return;
}

I have a simple AJAX function that sets $_POST['a'] equal to something. The var_dump($tutorid) properly displays the id from the url. However the $tutorid in the get_current_user_subjects is sending NULL.

If I try a var_dump like this to check $tutorid

$tutorid = $_GET['userid'];

//populate user tutoring subjects
if( isset($_POST['a'])) {
  echo json_encode($tutorid); return;
  // $currentsubjects = get_current_user_subjects( $tutorid );
  // unset($_POST['a']);
  // echo json_encode($currentsubjects); return;
}

Then I get NULL. If I hard code in a tutorid in the get_current_user_subjects( $tutorid ) (like add in 15 or something) the function returns data to console.log like expected but using the variable $tutorid stops it completely. I can't figure out why this is happening! Someone please enlighten me.

Here is the AJAX just incase. It works find on other pages so I am assuming the issue is with $_GET

$.ajax({
  url: 'profile.php',
  method: 'post',
  data: "a=true",
  dataType: 'json',
  success: function (x) {
    console.log(x);
  },
  error: function(a, b, c) {
    console.log(a);
    console.log(b);
    console.log(c);
  }
  • 写回答

2条回答 默认 最新

  • dqotv26286 2016-06-03 03:50
    关注

    Maybe you can use this method. So you can POST the userid

    $.ajax({
      url: 'profile.php',
      method: 'post',
      data: {a: a, userid:userid},
      dataType: 'json',
      success: function (x) {
        console.log(x);
      },
      error: function(a, b, c) {
        console.log(a);
        console.log(b);
        console.log(c);
      }
    

    So in your form before the action. you can set userid in hidden form

    <input type="hidden" name="userid" value="<?php echo $userid;?>" />
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图