Re: [PHP] Any Running Simple Ajax Sample for Php

[email protected] (paragasu)
Newsgroups php.general
Message-ID <[email protected]>
On Sat, May 3, 2008 at 4:31 AM, Jon L. <[email protected]> wrote:

> If you aren't already, I recommend putting to use a JS library with Ajax
> support.
> Nothing else, they can reduce the browser compatibility overhead coding
> you'll need to do.
>
> You can pick any of many, but I'm more familiar with Prototype:
> http://prototypejs.org/
>
> ## credits.php
> --------------------
> <?php
> /* ... */  // determine value for $credits
> print min($credits, 0);
> ?>
>
> ## credits.html
> ---------------------
> <html>
>  <body>
>    <div id="credits">Checking credits...</div>
>
>    <script src="prototype.js"></script>
>    <script type="text/javascript">
>    /*** Reference ***/
>    //// http://prototypejs.org/api/periodicalExecuter
>    //// http://prototypejs.org/api/ajax/request
>    //// http://prototypejs.org/api/element/observe
>
>    function creditsCheck(pe) {
>      new Ajax.Request('foobar.php', {
>        method: 'get',
>        parameters: {ts: (new Date()).getTime()}, // cache prevention
>        onSuccess: function (transport) {
>          var elem = $('credits');
>          if (Number(transport.responseText) > 0) {
>            elem.update('Credits remaining: ' + transport.responseText);
>          } else {
>            elem.update('Credits have expired.').setStyle({background:
> '#f00'});
>            pe.stop();
>          }
>        },
>        onFailure: function () {
>          $('credits').update('Could not determine
> credits.').setStyle({background: '#f00'});
>        }
>      });
>    }
>
>    document.observe('dom:loaded', function () {
>      var pe = new PeriodicalExecuter(creditsCheck, 60);
>      creditsCheck(pe); // first check
>    });
>    </script>
>  </body>
> </html>
>
> - Jon L.
>
> On Fri, May 2, 2008 at 4:13 AM, Heysem KAYA <[email protected]>
> wrote:
>
> > Hi,
> >
> > I would like to check each minute whether the user credit is finished
> and
> > update the relevant place on page. So I have downloaded however was not
> > able
> > to run some sample ajax code.
> >
> > Is there anyone who has such a simple code to implement?
> >
> >
> >
> > Thanks,
> >
> >
> >
> > Heysem Kaya
> >
> >
>

jQuery library also can do AJAX thing in relatively simple way. check
jquery.com
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.