passing parameters to a jquery javascript function?
i have this jquery function that i want to pass topic
parameter to, i just dont know how to pass it lol :)).
the jquery function:
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 开发者_StackOverflow社区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
}
}
});
}
and this is the url:
http://localhost/final/home.php#page2&topic=jquery
when i click this link, the page load fines(using jquery), but its not passing the topic parameter!
<h3 class="timeline"><?php echo $_GET["topic"]; ?> echo</h3>
so this wnt echo, because it cnt access the topic param!! if you guys know what i mean :))
You are using $_GET there but the ajax is using post.
What happens when you use this instead:
<h3 class="timeline"><?php echo $_POST["topic"]; ?> echo</h3>
Well this should do it
loadPage('http://localhost/final/home.php#page2?topic=jquery');
If not, there may be something wrong with your code.
EDIT
Okay I think it is to do with the URL you are passing to it, try this instead
loadPage('#page2&topic=jquery');
I hope that fixes it for you.
精彩评论