使用 Jquery 将变量从 PHP 文件传递​​到 php 文件 [英] Passing variable from PHP file to php file using Jquery

查看:34
本文介绍了使用 Jquery 将变量从 PHP 文件传递​​到 php 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 jquery 将一个变量从 file1.php 传递到 file2.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?

推荐答案

传递部分可能发生在定义变量的脚本中,所以在 file1.php 中.然后你会得到以下文件:

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;
?>

这篇关于使用 Jquery 将变量从 PHP 文件传递​​到 php 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆