Beginner Ajax question - getting value from href

Hello,

I’ve been fiddling around with ajax, I have little experience with htmlish languages so it takes some time to get into. I have followed some tutorials on w3schools and they have been very helpfull. There is just one problem, they all use form components to send info to javascript.

What I want to know is how to use href links to send information.
I have the following situation:

  • Data is loaded from a database, for each item from the database a href link is generated.
  • The ID from the item is stored in the href

<script type="text/javascript">
	
	function showData(ID){
		
	      //use ajax to send the variable to a php file which retrieves the corresponding data for the given ID
	}

</script>


<?php

include("connect.php");


	$query = "SELECT * from nieuws ORDER BY datum DESC";
	$result = mysql_query($query);
	
	//terwijl er resultate blijven zijn, echo de resultaten
	while($row = mysql_fetch_array($result)){


		
		?><a href = "javascript:showData('<?php  echo ''.$row['titel'].'' ?>' )" > <?php echo ''.$row['titel'].'' ?> </a>
	<?php
	} //end of while
	

?>

My solution is to make the link a javascript function which will take care of the ajax, but this doesn’t seem like an appropiate solution.

Any suggestions?
Thanks in advance