Reputation: 177
I'm creating a website for my uni final year project and I am having real problems with the one seemingly small thing.
I'm using php to create a forum table with a dynamic link with the following code;
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><a id="viewTopic.php?id=<? echo $rows['id']; ?>" href="viewTopic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></a><BR></td>
I want to use jquery to open the link from the table above in a div ajax style. I have done this successfully with other links using this code;
$("#forum").click(function(){
$("#subConList").html(loadAni).load('mainForum.php');
});
I Don't have a clue how to do this because of the php used in the href of the table link. Spent hours trying to sort this out. Any help suggestions would be great appreciated.
Thanks
I changed the tag to a button, shown below
<button id="topic<? echo $rows['id']; ?>" href="viewTopic.php?id=<? echo $rows['id']; ?>"><? echo $rows['topic']; ?></button>
This is the jquery i'm using to to try and load content to the #subConList Div.
$(document).ready(function(){
$("#topic<?php echo $rows['id']; ?>").click(function(){
$("#subConList").html(loadAni).load('viewTopic.php?id=<?php echo $rows['id']; ?>');
});
});
Upvotes: 3
Views: 136
Reputation: 4298
You can also use post function of jquery:
$("#forum").click(function(e){
e.preventDefault(); //Just to prevent page refreshing on link click
$.post('viewTopic.php', { id : 45 } function(data) {
$("#subConList").html(data);
});
}
Upvotes: 4
Reputation: 100175
Do you mean something like this:
$(document).ready(function() {
$("a").click(function(e) {
e.preventDefault();
$("#yourContainerDivId").load($(this).attr("href"));
});
});
Upvotes: 3