I need to display a query via AJAX and to be able to do that, i have to match the ID of the product. Thus i thought of performing a POST method via AJAX to allow the execution of the query.
Now i would like to do a trigger function for the AJAX such that the information will be shown on the page itself instead of being redirect to another page. How do i go about doing it ? I have added tried various place to add the Onclick function, however nothing seems to work.
Any suggestion ?
Thanks
echo '<a onclick="showUser('.$row['ID'].')" method = "POST" action= "viewComments.php">Show Comments</a>';
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("Post","viewComments.php?q="+str,true);
xmlhttp.send();
}
</script>