Jump to content

Recommended Posts

Hi, I am not the best with Javascript or Ajax I just want to perform a tiny thing. I want to know how can I pass a GET variable in an anchor tag to PHP Ill explain further below.



<script type='text/javascript'> 
function load() {
if (window.XMLHttpRequest)  {
	xmlhttp = new XMLHttpRequest();

	}else {

		xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
	}
		  
	xmlhttp.onreadystatechange = function()  {

		if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {

		document.getElementById('adiv').innerHTML = xmlhttp.responseText;

		  }
		}	  

xmlhttp.open('GET', 'include.inc.php', true);
xmlhttp.send();

}

</script>

</head>

<body>
<?php echo "<a href='#' onclick='load();'>click </a>" ?>
<div id='adiv'> </div>

 

 

Ok focus on this part which is <a href='#' onclick='load();'>click </a>. Instead of #  there would be some

primary number generated through mysql. For instance ?cid=25, ?cid=26 and so on you get the picture.

I want to know how can I pass these to my include.inc.php. Lastly I would like to know what should my url be for these to pass because I used to extact data from mysql and echo URLS as

<a href=' include.inc.php?$cid' > </a>  If I do this now wont this just directly take me to the page So what is the proper way of passing stuff. Thanks any help is appreciated hope I made some sense was kinda hard explaining!

 

Link to comment
https://forums.phpfreaks.com/topic/235097-a-little-help-with-anchor-tags/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.