I got the answer from this post [How to send or assign Jquery Variable value to php variable? but somehow my PHP can not get the value passed from Jquery this is html co
HTML:
comp1 comp2 comp3
JS:
$('a').click(function(){ $.ajax({ type: "POST", url: 'random.php', data: { name: $(this).attr('id') } }) .done(function( msg ) { alert( msg ); }); });
Use href="javascript:;" attr, or e.preventDefault(); inside event handler, to prevent the link executing.
href="javascript:;"
e.preventDefault();