473,471 Members | 4,650 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

PHP & AJAX

Hi,

I have a feeling this is a dumb question, but I am exploring AJAX and
PHP. I would like to write my PHP in an Object Oriented approach.
What is the limitation on what I can return in AJAX? Every example I
find seems to be text, which make sense because it is client side.
So, if I want to try to separate the presentation from the
application, I should call a PHP script using AJAX, and in that PHP
script have objects, call the objects methods and which return to the
PHP script, which returns it to the AJAX script.

So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP
script or can I simply put the objects in the $_SESSION?

Thanks for your help as I try to learn/understand this.

Kevin
Jan 17 '08 #1
4 2035
KDawg44 wrote:
Hi,

I have a feeling this is a dumb question, but I am exploring AJAX and
PHP. I would like to write my PHP in an Object Oriented approach.
What is the limitation on what I can return in AJAX? Every example I
find seems to be text, which make sense because it is client side.
So, if I want to try to separate the presentation from the
application, I should call a PHP script using AJAX, and in that PHP
script have objects, call the objects methods and which return to the
PHP script, which returns it to the AJAX script.

So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP
script or can I simply put the objects in the $_SESSION?

Thanks for your help as I try to learn/understand this.

Kevin
Kevin,

Web pages are transaction oriented. Every call to a web page, whether
it be via AJAX or a browser request, is a new transaction, and has
nothing in it other than what the browser sends.

Typically in web programming, you do not keep persistent objects
throughout the run. Rather, you create them as needed.

Two ways to keep track of things - store things in a cookie (typically
small amounts of text data on the browser) or in the session (text or
binary data). But either way, you don't want to store large amounts of
data, for performance reasons.

You can put objects in the session, as long as they don't contain
resources. But if there is a large amount of data, i.e. from a
database, it's generally better to keep a key in the session and
retrieve the data when it is required.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 18 '08 #2
KDawg44 wrote:
So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP script
or can I simply put the objects in the $_SESSION?
Yes, you may persist objects in $_SESSION.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 18 days, 10:00.]

Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/
Jan 18 '08 #3
On Jan 17, 7:14 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
KDawg44 wrote:
Hi,
I have a feeling this is a dumb question, but I am exploring AJAX and
PHP. I would like to write my PHP in an Object Oriented approach.
What is the limitation on what I can return in AJAX? Every example I
find seems to be text, which make sense because it is client side.
So, if I want to try to separate the presentation from the
application, I should call a PHP script using AJAX, and in that PHP
script have objects, call the objects methods and which return to the
PHP script, which returns it to the AJAX script.
So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP
script or can I simply put the objects in the $_SESSION?
Thanks for your help as I try to learn/understand this.
Kevin

Kevin,

Web pages are transaction oriented. Every call to a web page, whether
it be via AJAX or a browser request, is a new transaction, and has
nothing in it other than what the browser sends.

Typically in web programming, you do not keep persistent objects
throughout the run. Rather, you create them as needed.

Two ways to keep track of things - store things in a cookie (typically
small amounts of text data on the browser) or in the session (text or
binary data). But either way, you don't want to store large amounts of
data, for performance reasons.

You can put objects in the session, as long as they don't contain
resources. But if there is a large amount of data, i.e. from a
database, it's generally better to keep a key in the session and
retrieve the data when it is required.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
Jerry,

Thanks so much for your responses. You are always such a helpful
resource. I understand OO programming but as a young professional
(whose mainstay is sys admin and network engineering and not
programming) unfortunately putting it into practice with databases is
something i have not really done and using OO concepts in web
programming I have not done at all.

So the best bet, if I understand you clearly, is to create a hash
table with a key and some data (whatever the primary key in the DB is
maybe?) that allows me to quickly pull that data from the DB again and
load it back in to the PHP object?

Thanks for the help.
Jan 18 '08 #4
KDawg44 wrote:
On Jan 17, 7:14 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>KDawg44 wrote:
>>Hi,
I have a feeling this is a dumb question, but I am exploring AJAX and
PHP. I would like to write my PHP in an Object Oriented approach.
What is the limitation on what I can return in AJAX? Every example I
find seems to be text, which make sense because it is client side.
So, if I want to try to separate the presentation from the
application, I should call a PHP script using AJAX, and in that PHP
script have objects, call the objects methods and which return to the
PHP script, which returns it to the AJAX script.
So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP
script or can I simply put the objects in the $_SESSION?
Thanks for your help as I try to learn/understand this.
Kevin
Kevin,

Web pages are transaction oriented. Every call to a web page, whether
it be via AJAX or a browser request, is a new transaction, and has
nothing in it other than what the browser sends.

Typically in web programming, you do not keep persistent objects
throughout the run. Rather, you create them as needed.

Two ways to keep track of things - store things in a cookie (typically
small amounts of text data on the browser) or in the session (text or
binary data). But either way, you don't want to store large amounts of
data, for performance reasons.

You can put objects in the session, as long as they don't contain
resources. But if there is a large amount of data, i.e. from a
database, it's generally better to keep a key in the session and
retrieve the data when it is required.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================

Jerry,

Thanks so much for your responses. You are always such a helpful
resource. I understand OO programming but as a young professional
(whose mainstay is sys admin and network engineering and not
programming) unfortunately putting it into practice with databases is
something i have not really done and using OO concepts in web
programming I have not done at all.

So the best bet, if I understand you clearly, is to create a hash
table with a key and some data (whatever the primary key in the DB is
maybe?) that allows me to quickly pull that data from the DB again and
load it back in to the PHP object?

Thanks for the help.
That's what I generally do. But no need to create a hash value. Each
table should already have a primary key (typically an automatically
numbered column) which is all you need to identify the data. Just pass
that in the $_SESSION, i.e. as $_SESSION['datakey'];

Transactional programming is quite a bit different from what most
programmers are used to.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Jan 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: k.mitz | last post by:
Hi, I have a PHP application that allows users to generate a .pdf report of their database content. Normally, I've had to refresh a page to call the script to generate the report, so there's a...
21
by: javainfo | last post by:
How can i refresh IFRAME and load data through AJAX?
10
by: Steve | last post by:
I need to build a very dynamic client and would be interested in knowing the pros and cons of using JSF and Ajax to accomplish this. Thanks. Steve
13
by: Sharon | last post by:
Hi all, I was wondering if anyone had experience using ajax with asp.net controls. What i'm looking for, are ways to implement and possible problems. A way to implement could be rendering the...
3
by: Ivan P | last post by:
Hello! I have a index.php that on one click calls via AJAX a file.php. index.php looks like this: <html > <head> <script language="javascript" type="text/javascript" >
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
2
by: =?Utf-8?B?RG90TmV0RGV2?= | last post by:
Hi, We are still using .net 1.1 and I am working on a problem that I thought could be 'probably' done easily through 'AJAX'. I visited the ajax.asp.net site and I got an impression that its only...
18
by: Andrew Wan | last post by:
I have been developing web applications with ASP & Javascript for a long time. I have been using Visual Studio 2003.NET. While VS2003 is okay for intellisense of ASP & Javascript, it's still not...
0
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.