php - 将参数传递给 jquery javascript 函数?

标签 php javascript jquery url get

我有这个 jquery 函数,我想将 topic 参数传递给它,我只是不知道如何传递它 lol :))。

jquery函数:

function loadPage(url)  //the function that loads pages via AJAX
{
    url=url.replace('#page','');    //strip the #page part of the hash and leave only the page number

    $('#loading').css('visibility','visible');  //show the rotating gif animation

    $.ajax({    //create an ajax request to load_page.php
        type: "POST",
        url: "load_page.php",
        data: 'page='+url,  //with the page number as a parameter
        dataType: "php",    //expect html to be returned
        success: function(msg){

            if(parseInt(msg)!=0)    //if no errors
            {
                $('#change-container').html(msg);   //load the returned html into pageContet
                $('#loading').css('visibility','hidden');   //and hide the rotating gif
            }
        }

    });

}

这是网址:

http://localhost/final/home.php#page2&topic=jquery

当我点击这个链接时,页面加载正常(使用 jquery),但它没有传递主题参数!

<h3 class="timeline"><?php echo $_GET["topic"]; ?> echo</h3>

所以这个 wnt echo,因为它不能访问主题参数!!如果你们知道我的意思:))

最佳答案

你在那里使用 $_GET 但 ajax 使用的是 post。

当你改用它时会发生什么:

<h3 class="timeline"><?php echo $_POST["topic"]; ?> echo</h3>

关于php - 将参数传递给 jquery javascript 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3778393/

相关文章:

php - session 在 php 中经过一段时间后自动过期

php - 将项目从 windows-1256 转换为 utf-8 字符集,正确的步骤是什么?

javascript - 代理从 webpack 开发服务器到 .net MVC 站点的请求

javascript - 将字符串的第一个字符复制到另一个 div jquery 或 javascript

php - 转换脚本

PHP 图片 uploader 不适用于 Capital JPG 扩展

javascript - 如何在没有拼接的情况下更新数组(angularjs)元素?

javascript - Div下拉菜单相互干扰

php - 不允许选择任何选定值

javascript - 回调时变量值的反转