将值从Jquery发布到变量PHP

时间:2017-02-09 04:10:44

标签: php jquery html ajax

我想在点击按钮时发布一个值, 因此,当我点击<a id="link1"> Page Home </a>时,它会将值发送到自定义变量php

例如:

<?php
$linkredirect = ''; //it will send to php include
?>
<ul>
    <li><a id="link1"> Home </a></li>
    <li><a id="link2"> Profile </a></li>
    <li><a id="link3"> Contact </a></li>
</ul>

<?php include ($linkredirect); ?>
as far as I know the jquery:
$(function() {
    $('#link').click(function() {
        $.post($linkredirect)
        // in this column that I do not know 

    });
});

你能帮我填一下这些变量吗?点击了吗?

我想要的细节是,导航是固定的但是attr主体将随着<?php include();?>

而改变

1 个答案:

答案 0 :(得分:0)

<?php
$page_num = isset($_GET['pageNum']) ? $_GET['pageNum'] : NULL;
if (!is_null($page_num)) {
    $linkredirect = NULL;
    switch ($page_num) {
        case 1:
            $linkredirect = 'home.php';
            break;
        case 2:
            $linkredirect = 'profile.php';
            break;
        case 3:
            $linkredirect = 'contact.php';
            break;
        default:
            break;
    }
}


?>
<ul>
    <li><a href="?pageNum=1"> Home </a></li>
    <li><a href="?pageNum=2"> Profile </a></li>
    <li><a href="?pageNum=3"> Contact </a></li>
</ul>
<?php
    if (!is_null($linkredirect)) {
        include($linkredirect );
    }
?>