How do i prevent the anchor tag from reloading my page when i click it using js
<a href='?code=$user_code' class=''>view user</a>
Like Barmar suggested in the comments, you can add an event listener to the anchor element that calls event.preventDefault() to prevent page reload. Inside the event listener you can fetch the data from database.
<a id="my-anchor" href='?code=$user_code'>view user</a>
var myAnchor = document.getElementById('my-anchor');
myAnchor.onclick = function(e) {
e.preventDefault();
var href = myAnchor.getAttribute('href');
// fetch data from database
};
https://jsfiddle.net/tojx5ske/
Another option is to create an anchor with href="#" and pass the real href to the event listener using data attributes:
<a id="my-anchor" href="#" data-href='?code=$user_code'>view user</a>
var myAnchor = document.getElementById('my-anchor');
myAnchor.onclick = function(e) {
var href = myAnchor.dataset.href;
// fetch data from database
};