doushan1863 2016-01-21 22:44
浏览 34
已采纳

使用Jquery将变量从PHP文件传递到php文件

I want to pass a variable from file1.php to file2.php using jquery.

file1.php

<?php
    $user_rank = $rank;
?>

file2.php

<?php
    $user_rank = $_GET['user_rank'];
?>

AJAX

function getRank()
{
$.ajax({
       type: "GET",
       url: "file2.php",
       data: ?????,
       success: function(result){
         $("#TargetRank").html(result);
       }
     });         
};

Can anyone help me with this?

  • 写回答

4条回答 默认 最新

  • dongpu1881 2016-01-21 22:49
    关注

    The passing part can happen in the script where the variable is defined, so in file1.php. Then you get the following files:

    file1.php:

    <?php
    $user_rank = 123;
    ?>
    <script>
    function getRank()
    {
    $.ajax({
           type: "GET",
           url: "file2.php?user_rank=<?php echo $user_rank; ?>",
           success: function(result){
             $("#TargetRank").html(result);
           }
         });         
    };
    </script>
    

    file2.php:

    <?php
    $user_rank = $_GET['user_rank'];
    echo $user_rank;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据