douchang8758 2018-08-24 17:33
浏览 50

从$ _GET方法获取ajax中php文件头的值

Hi friends I am is a beginner in AJAX so I am Facing some problem which is I am unable to take the values from the header of the page which was sent be $_GET method ..Help me Please to find out the Solution

here is my PHP Code

<?php include '../../db_connect/connection.php'; ?>

<?php

$select = "SELECT * FROM leave_requests WHERE teacher_name = '$teacher_id' ORDER BY id DESC";
$select_result = mysqli_query($connection,$select);
while ($row = mysqli_fetch_assoc($select_result)) {
    $date = $row['date'];
    $teacher = $row['teacher_name'];
    $days = $row['days'];
    $reason = $row['reason'];
    $status = $row['status'];
    $type_of_leave = $row['type_of_leave'];

    $principal_remarks = $row['principal_remarks'];
    $id = $row['id'];
    ?>

    <td><?php echo $date; ?></td>
    <td><?php echo $days; ?></td>
    <td><?php echo $type_of_leave; ?></td>
    <td><?php echo $reason; ?></td>


    <td><?php echo $status; ?></td>
    <td><?php echo $principal_remarks; ?></td>
    </tr>

<?php
} ?>

and this is my incomplete AJAX code

<script type="text/javascript">
$(document).ready(function(){
    $.ajax({
        url:'display_leave_request_response.php',
        data:
    });
});
</script>

how can I grab the values which is comming in a get request in the header using Ajax please explain

sorry for coping the things since the system is not accepting the question so I have to do this

if there is any mistakes in the code then please explain it to me

  • 写回答

1条回答 默认 最新

  • doufangzhang4454 2018-08-24 17:38
    关注

    Set the data: option to an object containing the parameters you want to send:

    data: { teacher_id: some_variable }
    

    Then in PHP you can use:

    $teacher_id = $_GET['teacher_id'];
    

    You should also learn to use a prepared statement instead of substituting the $teacher_id variable directly into the SQL, to prevent SQL injection. See How can I prevent SQL injection in PHP?

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么