ok, So Im very new to this whole AJAX kind of thinking, and I might be trying to do something that's either harder than it needs to be, or theres an easier way that I havent fount yet...

I'm trying to make a generic javascript function to call php functions....
Please excuse my psudo code, but I just want to get the picture if this kind of thing might work... or if I should be focusing elsewhere... any ideas?

PHP

// php Page of Functions
function doSomething1() { }
function doSomething2($variable) { //update database with $variable }
 ...
MoreFunctions() { }
...

javascript

function getxmlhttp()
{
	...
	return xmlHttp;
}

function call_php_function(phpPageOfFunctions, funcName(withphpvariables))
{
	xmlhttp = getxmlhttp();
	xmlhttp.open(... "phpPageOfFunctions" ...);
	
         CallTheGivenFunctionFromPage(funcName);
}

Html

<input type="button" onClick="call_php_function(phpfunctions.php,doSomething2(75));">

Has anyone implemented this kind of method?
Is there something else I should be searching for to get some insight?
any thoughts?
Thanks

i use this:

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;
}


function Ajaxfunction(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Browser does not support HTTP Request");
  return;
  }
var url="http://www.myURL.com/file.php";
url=url+"?q="+str;

xmlhttp.onreadystatechange = stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

just change the url and play with the parameters

May be better to use some free javascript toolkit to study how it works and faster get result like : Prototype or jQuery or Mootols or Dojo

Thanks guys! that helped out a lot.. I'll definitely be looking up those toolkits!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.