My code works but if I click on link 1, link 1's data should show in the div. If I click on link 2, link 1's data will disappear and link 2's data will be displayed. But the way the code is working, link 1's data shows up and then link 2's data will show up underneath it and neither will disappear.
The SQL:
if(isset($_GET['id']))
{
$sql_query="SELECT * FROM PresidentialCandidate WHERE ID=".$_GET['id'];
$result_set=mysqli_query($mysqli,$sql_query);
$row=mysqli_fetch_array($result_set,MYSQLI_ASSOC);
}
The Ajax:
jQuery(document).ready(function() {
jQuery('a.query-link').on('click', function(e){
//Prevent the link from working as an anchor tag
e.preventDefault();
//Declare 'this' outside of AJAX because of asynchronous nature of call
that = jQuery(this);
//Make AJAX call to the PHP file/database query
jQuery.ajax({
url:'http://dirtypoliticsph.com/chart-submission/templatecode.php',
type:'GET',
data:{id:jQuery(this).attr('data-id')},
success:function(data){
jQuery('#myStyle').append(data);
}
});
});
});
appendwithhtml.appendadds wherehtmlwill replace.html(data)instead ofappend(data)append()does?