1 Replies - 613 Views - Last Post: 25 July 2010 - 07:13 AM

#1 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Consolidating ajax calls

Posted 24 July 2010 - 07:32 AM

I have several ajax calls on a page and I'd like to consolidate the functions. For example each ajax call has a function that looks similar to this one:
function changemyemail(mynewemail, mynewphone, myconfirm)
{
	httpObject = getHTTPObject();
	if (httpObject != null) 
	{
		httpObject.open("GET", "changeemail.php?email="+mynewemail+"&myphone=" + mynewphone + "&confirm="+myconfirm);
		httpObject.send(null);
		httpObject.onreadystatechange = setregister;
	} else {
		alert("oops!");
	}
}



I'd like to have them all use a single generic function:
function changesomething(myphpurl, setchangedstate)
{
	httpObject = getHTTPObject();
	if (httpObject != null) 
	{
		httpObject.open("GET", myphpurl);
		httpObject.send(null);
		httpObject.onreadystatechange = setchangedstate;
	} else {
		alert("oops!");
	}
}


but I can't get setchangedstate to point to a function.

Is This A Good Question/Topic? 0
  • +

Replies To: Consolidating ajax calls

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3103
  • View blog
  • Posts: 10,899
  • Joined: 08-August 08

Re: Consolidating ajax calls

Posted 25 July 2010 - 07:13 AM

Hmm, I stil need to do more testing on it, but using eval seems to work:
function changesomething(myphpurl, setchangedstate)
{
	httpObject = getHTTPObject();
	if (httpObject != null) 
	{
		httpObject.open("GET", myphpurl);
		httpObject.send(null);
		httpObject.onreadystatechange = eval(setchangedstate);
	} else {
		alert("oops!");
	}
}


:clap:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1