3

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']; ?>');     
    });
});

2 Answers 2

4

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);
});
}
Sign up to request clarification or add additional context in comments.

Comments

3

Do you mean something like this:


$(document).ready(function() {
  $("a").click(function(e) {
     e.preventDefault();
     $("#yourContainerDivId").load($(this).attr("href"));
  });
});

1 Comment

if it worked the way you want you can mark the answer as Accepted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.