2009/6/25 Robaj <robrass...@gmail.com>

>
> Ok I got the gist of it, you can't do what I wanted to do, interact
> with php through ajax after the page has loaded. Yes I know it can get
> strings and data from the server side code, but only if that content
> is html.
>
> eval doesn't work with files loaded after the page is loaded.
> and
> file_get_contents() is realy no different to what I was doing with an
> fread().
>
> Ajax-php looks a great mix at first. But actually it isn't mixed at
> all really.
>
> When someone launches into your web site you can have any amount of
> php preprocessing.
> Then once loaded you enter a world where only ajax-javascript-html
> exist, ok you can reload the page to update the page in the way it was
> always done, but ajax plays no part in that. I can't help wondering
> why no one has taken a next step.
>

I think we have a communication problem.

Just so you DO get the point, several of my sites run from 1 URL.

www.site.com/index.php

That's it.

1 PHP script.

Ok, there are a ton of libraries and templates behind all of that.

This 1 script supports users with/without CSS/JS. It provides
SOAP/JSON/JSON-P access. It outputs CSS, JS, images, HTML, JSON, JSON-P,
etc.

Once a page is loaded, you *CAN* interact with PHP using AJAX. You just have
to understand how things work.

The http protocol is known as "stateless". Essentially, this means every
request made is, in itself, completely unconnected to any/every other
request going on.

You add "state" by the use of sessions (normally a cookie with an sessionid
on the client linking to some sort of session store on the server). When the
cookie is sent to the server, the server can retrieve any previously stored
data for that session, effectively restoring the "state".

There are other techniques where all the "state" data is passed with every
request, making the client the store.

There is nothing stopping you from running PHP code on the server in
response to user activity via AJAX (can we all say autocompletion).

There is nothing stopping you from generating JSON encoded output in PHP so
that the client gets a block of data for processing. Say you have a page
showing products, as the user chooses different products from a list, an
AJAX request fires off to the server, sends the product details back to the
client encoded using json_encode($a_ProductData, JSON_FORCE_OBJECT) and the
client uses the data, in conjunction with a template to replace the existing
product details. No HTML is passed, just JSON (which is just JS really).

There is nothing stopping you from using a clever pattern called JSON-P.
This allows you to have various clientside JS facilities callable by the
server.

So. Full communication, in both directions.

Whatever you want.

Really.

And prototype can support it all.

Regards,

Richard.

>
>
> On Jun 24, 11:15 am, Richard Quadling <rquadl...@googlemail.com>
> wrote:
> > 2009/6/24 Alex McAuley <webmas...@thecarmarketplace.com>:
> >
> >
> >
> >
> >
> > > I really think you are overthinking this!
> >
> > > If you want to echo out "<?php echo('FOO'); ?> for instance and have
> the
> > > preprocessor parse it... you need to (dangerously) eval it ....
> >
> > > $variable="<?php echo('<p>foo</p>'); ?>";
> >
> > > eval($variable);
> >
> > > ....... "<p>foo</p>" is returned to the browser...
> >
> > > So (and i highly do not recommend this unless you truely trust the text
> in
> > > your database and the files it is opening) u must use php's eval();
> >
> > > Like so ... (using your variables)
> >
> > > eval($retstr);
> >
> > > then anything inside that variable or file will be evall'd as opcode
> and
> > > passed through the pre-processor and you will be left with html or
> whatever
> > > your php code spits out!
> >
> > > HTH
> >
> > > Alex
> >
> > > ----- Original Message -----
> > > From: "Robaj" <robrass...@gmail.com>
> > > To: "Prototype & script.aculo.us" <
> prototype-scriptaculous@googlegroups.com>
> > > Sent: Wednesday, June 24, 2009 7:44 AM
> > > Subject: [Proto-Scripty] Re: php in files
> >
> > > Ok, let me put my idea to you and see if there is a way without
> > > reloading the whole page -
> >
> > > I use prototype.js and project.js. project.js is just my entensions
> > > for each project, which I have narrowed down to two functions,  -
> >
> > >            function myRequest( text ) {
> > >                new Ajax.Request('requests.php',
> > >                {
> > >                    method: 'post',
> > >                    postBody: text,
> > >                    onComplete: myResponse
> > >                });
> >
> > >            }
> > >            function myResponse(req) {
> > >                $(targetdiv).innerHTML= req.responseText;
> > >            }
> > > Where text is supplied from the controls, such as 'page=home'.
> > > request.php is the only php file called directly, it decides which
> > > response is wanted and returns the text for a control or entire body
> > > for <div id='mainbody'></div>
> >
> > > All of my pages and controls within them are created in php from the
> > > database. This is very easy to maintain and update, so a nice base for
> > > all kinds of applications
> >
> > > All works well if I only respond with html including the ajax side
> > > that recalls requests.php, the only problem is that I intended some of
> > > the pages to be applications, so I want them to have php and can not
> > > see a way to pass it through the preprocessor.
> >
> > > My request.php at the server side is like this -
> >
> > > $Home=$button=$update=$testButton=$menuItem="";
> > > extract($_POST,EXTR_IF_EXISTS);
> >
> > > if($menuItem != "")
> > > {
> > >    $retstr = "";
> >
> > >    $dbconn = getdbconnection();
> >
> > > //find page associated with this menu item
> > >    $query = 'SELECT body FROM menu WHERE name=\''.$menuItem.'\'';
> > >    $result = pg_query($dbconn,$query) or die('Query failed: ' .
> > > pg_last_error());
> > >    $row = pg_fetch_row($result);
> > >    //read in the file
> > >    if(file_exists($row[0]))
> > >    {
> > >        $handle = fopen($row[0],"r");
> > >        $retstr = fread($handle,filesize($row[0]));
> > >        fclose($handle);
> > > //failed attempt to use include instead
> > >        //$retstr = "<?php include ".$row[0]."; ?>";
> > >    }
> > >    else
> > >    {
> > >        $retstr = "File not created yet";
> > >    }
> > >    pg_close($dbconn);
> > >    echo $retstr;
> > > }
> >
> > > In the end this would leave me with only one main page index.php and
> > > all other pages called up via ajax and created or loaded via php.
> >
> > > I have the feeling now that I have to update the whole page, not a
> > > terrible tragedy, but I just have the feeling that I can somehow put
> > > my fread() file through the php preprocessor.
> >
> > > On Jun 23, 3:09 pm, Richard Quadling <rquadl...@googlemail.com> wrote:
> > >> 2009/6/23 Robaj <robrass...@gmail.com>:
> >
> > >> > I know this isn't strictly speaking a Prototype issue, but this is
> the
> > >> > only group I am in and a few topics do skirt around the edges of
> your
> > >> > main topic.
> >
> > >> > If I have a file -
> > >> > home.php
> > >> > <?php
> > >> > echo "<h1>A very interesting home page</h1>";
> > >> > ?>
> >
> > >> > Then the file is returned to go into <div id="mainbody"></div> with
> a
> > >> > plain fread() into a variable which is 'echo'd back to the client.
> >
> > >> > 'include'ing this file is fine, but then it passes through php at
> the
> > >> > same time as everything else.
> >
> > >> > But any such file loaded as the action of an Ajax call is not fine.
> It
> > >> > doesn't get passed via php, or at least I don't think it does -
> > >> > because in 'mainbody' I get part of it such as
> >
> > >> > Interesting"; ?>
> >
> > >> > Confusing because if it were being passed through php I would expect
> > >> > 'Interesting'. but if it were not, then I would expect the whole
> file
> > >> > in plain text.
> >
> > >> > I knew when I did this with fread I was probably heading for
> trouble,
> > >> > but which is happening,
> > >> > partial php parseing,
> > >> > no php parseing or
> > >> > ..... ?
> >
> > >> If you use fread(), you are reading a file. Any file. Nothing magic.
> > >> No processing.
> > >> If you use include()/require()/include_once()/require_once(), then PHP
> > >> will process that file if it contains a valid opening tag (<?php).
> >
> > >> Uploading a file does NOT process the file. The file is only processed
> > >> when it is requested.
> >
> > >> Can you provide any more information about what you are trying to do?
> >
> > >> Maybe using the PHP General list would also be a better place for this
> > >> thread? (http://docs.php.net/mailing-lists.php)
> >
> > >> Regards,
> >
> > >> Richard.
> >
> > >> --
> > >> -----
> > >> Richard Quadling
> > >> Zend Certified Engineer :
> http://zend.com/zce.php?c=ZEND002498&r=213474731
> > >> "Standing on the shoulders of some very clever giants!"
> >
> > Rather than ...
> >
> >        $handle = fopen($row[0],"r");
> >        $retstr = fread($handle,filesize($row[0]));
> >        fclose($handle);
> > //failed attempt to use include instead
> >        //$retstr = "<?php include ".$row[0]."; ?>";
> >
> > Try ...
> >
> >        $retstr = include $row[0];
> >
> > I don't know what $row[0] contains. Nor what the file $row[0]
> > contains. That would be required for a better idea.
> >
> > Ideally you should follow a pattern (or a rule). Files with .php are
> > included otherwise they are raw content and should be ...
> >
> > $retstr = file_get_contents($row[0]);
> >
> > sort of thing.
> >
> > --
> > -----
> > Richard Quadling
> > Zend Certified Engineer :
> http://zend.com/zce.php?c=ZEND002498&r=213474731
> > "Standing on the shoulders of some very clever giants!"
> >
>


-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to