Call a specific PHP function with AJAX?

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Sep 2008
Posts: 7
Reputation: bdicasa is an unknown quantity at this point 
Solved Threads: 0
bdicasa bdicasa is offline Offline
Newbie Poster

Call a specific PHP function with AJAX?

 
0
  #1
Dec 23rd, 2008
Hi guys,

I was wondering if it was possible to call a specific PHP function using AJAX instead of calling a whole page. An example:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function MakeRequest()
  2. {
  3. var xmlHttp = getXMLHTTP();
  4.  
  5. xmlHttp.onreadystatechange = function()
  6. {
  7. if(xmlHttp.readyState == 4)
  8. {
  9. document.getElementById('provinceDiv').innerHTML =
  10. xmlHttp.responseText;
  11. }
  12. }
  13.  
  14. xmlHttp.open("GET", "FindProvinces.php", true);
  15. xmlHttp.send(null);
  16. }

I already have a PHP function (in a class) that retrieves the provinces/states from the database based on the country. I was wondering if it was possible to call this function instead of having to make a new file (in this case FindProvinces.php) that calls the function. Thanks in advance.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,626
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 468
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Call a specific PHP function with AJAX?

 
0
  #2
Dec 24th, 2008
I am sure PHP has some sort of MVC architecture implementation wherein the controller handles the requests and delegates it to an appropriate entity.
  1. // Here /operations is mapped to a PHP file which acts as a
  2. // controller and performs the delegation activity based on
  3. // the operation requested, here, find-provinces
  4. xmlHttp.open("GET", "/operations/find-provinces", true);
  5. xmlHttp.send(null);
Maybe posting this PHP related query in the PHP sub-forum might bring out some good responses since this seems more like a server-side url mapping/configuration issue.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC