Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery ajax php need help please

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']; ?>');     
    });
});
like image 440
Ciaran Avatar asked Aug 31 '26 21:08

Ciaran


2 Answers

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);
});
}
like image 89
username Avatar answered Sep 03 '26 11:09

username


Do you mean something like this:


$(document).ready(function() {
  $("a").click(function(e) {
     e.preventDefault();
     $("#yourContainerDivId").load($(this).attr("href"));
  });
});
like image 37
Sudhir Bastakoti Avatar answered Sep 03 '26 12:09

Sudhir Bastakoti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!