0

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by boomop
0

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

0

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

1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.