I have a div
which displays articles that contain anchor tags that are the "like" and "dislike" buttons. I want to update the div
when some clicks like or dislike without having to refresh the entire page. Here is the div
:
#Print out article and display information
echo "<article style='border: 2px solid #10466C;' class='topContent'>
<header>
<a class='article_title' href='article.php?article=$id'><h3>$title</h3></a>
</header>
<p class='date-author'>Date: $date <br /> Author: <span style='color: #10466C;'>$author </span> | Catagory: <a href='#'>$catagory</a> | Writer Level: $level<br />
Comments: ($cmt_total) </p>
<content>
<img class='article-image' src='$image' />
<div style = 'float: left; margin-left: 3%; width: 45%;'>
<div class='like_box'>
<a href='vote.php?vote=like&title=$title'><img src='img/like.png' class='vote'></a><p class='vote_text'>$like_num</p>
<p style='color: #fff;'>$like_username</p>
</div>
<div class='dislike_box'>
<a href='vote.php?vote=dislike&title=$title'><img src='img/dislike.png' class='vote'></a><p class='vote_text'>$dislike_num</p>
<p style='color: #EC2800;'>$dislike_username</p>
</div>
</div>
<div style='display: inline-block; margin-top: 10px;'>
$text<a href='article.php?article=$title'><b>read more</b></a>
</div>
</content>
<br />
<br />
</article> ";
}
If you look at the div
s called "like_box" and "dislike_box" you can see inside the anchor tag that is liked to the PHP script.
My question is how do I run that script without having to refresh the page and redirect using the header tags. Any help is appreciated and any extra information you may need I am willing to provide. I have tried many ways I know it will require AJAX or JavaScript it doesn't matter to me which one.
Thanks.