我有这个 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/