Jump to content

PHP/aJAX - GET


pengu

Recommended Posts

Don't actually know if this is possible.

Going to post snippets, tell me if more code is required.

 

I have a page called profile.php

It shows your profile, I have a link called edit.  Upon clicking it, I want aJAX to refresh the DIV with some information obtained from 'functions.php'.

 

Snippet of profile.php

		<div class=\"pLine\">
			<b>Profile Options</b> <a href=\"javascript:editProfile(test)\">[+] Edit</a><br />
		</div>

		<div id=\"myProfile\">
			<br />
			<b>Email:</b> " .$row['email']. "<br />
			<b>Date Joined:</b> <i>" .$row['date_joined']. "</i><br />
			<b>Clan:</b> z<br /><br /><br />
		</div>

 

functions.js

function editProfile(str)
{
	if (str=="")
		{
		  document.getElementById("myProfile").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("myProfile").innerHTML=xmlhttp.responseText;
				}
		}
	xmlhttp.open("GET","functions.php?q="+str,true);
	xmlhttp.send();
}

 

functions.php

<?php

$q = $_GET['q'];

	switch ($q)
		{
		case 'test':
		echo "<div class=\"important\">This worked!</div>";
		break;
		}

?>

Link to comment
https://forums.phpfreaks.com/topic/205615-phpajax-get/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.