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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)