Regarding my post ajax question

i’ve been reading up with learning ajax and found this neat tutorial on w3c schools with working with ajax with php i was reading though and php is straight forward however the ajax part wasnt

here is my ajax code


var xmlhttp;

function showUser(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="getuser.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged()
{
if (xmlhttp.readyState==4)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

My Question is this if i want the following function to do 2 things

1st.i want to be pass the id of a html div to this function
2nd i want to be able to include php code not using include php function since the function i am wanting to include a php function into this page since its already defined ni my php functions file called userprofile($user) ive seen many tutorials do it it from another url or address espcially when i am working with a joomla it display my entire content.
3.Refresh that spefeic div every 2 seconds,

So what would i need to change the above in order to get the above since most ajax functions ive seen only deals with including other php files in a ajax script not php functions

so my question can this be done?

Thanks,William