Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-30-2012, 08:47 PM   PM User | #1
TylerB
New Coder

 
Join Date: Aug 2012
Location: Kalamazoo, MI
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
TylerB is an unknown quantity at this point
Procedural PHP with AJAX

I am fairly new to PHP and thus not very experienced with the Object Oriented style. I am writing a web app in procedural PHP and I would like to add some AJAX functionality in it.

How can I use AJAX with procedural PHP? I have found MANY tutorials on how to use it with OOP, but that is not what I am trying to do. Can someone point me in the right direction of a tutorial or give me some tips/examples of AJAX with procedural PHP?

Any help/tips/examples are greatly appreciated!
TylerB is offline   Reply With Quote
Old 10-30-2012, 11:01 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,747
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
The concept is still identical. JS -> script -> results to JS.
The end result of an AJAX lookup is simply the output of the script provided. The PHP script simply needs to output what the JS wants to get, whether it be simple plain text, JSON format or XML or whatever.
OOP is quite easy to write an object into XML as you can write a method or chain it to the __toString and print it out and it will convert the object properties into a nice little XML package. Arrays can do this just as easily, a simple recursive method to build the XML string.
Frankly, the PHP is the easy part of the AJAX equation. Write the PHP as you would normally and even allow it to function as a standard PHP script. You can use an input from get or post to indicate it is ajax and trim it down if it is (if desired, will help on the size of the output). Then AJAX simply asks for this page and parses the results. This is honestly the more difficult part, but so long as you know what the AJAX is planning to do with it, it is a relatively simple task to perform.

So what I'm getting at here is that OOP versus procedural is ultimately no different. Its the parsed response that you are interested in; how you get there is completely up to you. I'm a huge OOP fan, but procedural definitely has its place (and is less code, less memory intensive, and [more often than not] easier to do).
Fou-Lu is offline   Reply With Quote
Old 11-01-2012, 08:04 PM   PM User | #3
TylerB
New Coder

 
Join Date: Aug 2012
Location: Kalamazoo, MI
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
TylerB is an unknown quantity at this point
Thank you very much. You just cleared up some major questions I had regarding the topic.
TylerB is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, oop, php, procedural

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:39 PM.


Advertisement
Log in to turn off these ads.