Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am trying to create a favorite and not favorite button.

A dull star - not favorite
A bright star - Favorite

So on clicking a dull star, database is updated and a bright star is displayed and now on clicking bright star, database is updated and dull star appears.

I am using following code -

<pre lang="Javascript">
<script type="text/javascript">
	
	
	function favourite()
	{
	var xmlhttp;
	var js_aid = "<?php echo $aid; ?>";
	 var js_user = "<?php echo $user; ?>";
	 
	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("myDiv").innerHTML=xmlhttp.responseText;
		document.getElementById("mybutton").style.display ='none';

		}
	  }
	xmlhttp.open("GET","http://test.xyz.php?aid="+ js_aid + "&user=" + js_user,true);

	xmlhttp.send();
	}


In xyz.php page I have added sql query to update the records and the display dull star. Now what I don't understand is where should i add notfavorite function so that it all happens asynchronously..

Thanks
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900