Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Ajax Programming

Really generic question PHP and AJAX


Hello, I am really new to ajax. I've used before some ajax scripts but
I 've never written something of my own so I need some help to do that.

What I am trying to do is display the result of a php function either
at specific interval (e.g. 5 seconds) or whenever a new record is added
in the DB.

So to be more specific. users log in and post questions. From the other
side the backend system sits there and an operator instead of having to
refresh tha page or use a javascript refresh waits to see the next
message he wants to answer.

Also a counter that counts the new messages refreshes. I suppose that
if I had that counter to update every seccond nomatter if there is a
new row or not will increase the load to the server and the client. So
if there was a way to run the update only when there is something new.
IT would be great.

What I've done is downloaded sajax toolkit and used a date example it
has that updates every second but it is really complicated.
I don't understand fully the following code and I wonder if there is an
alternative way.
Or from your experience if I can use a beeter toolkit, or even not use
a toolkit at all.
                        function show_me(date_server) {
                                document.getElementById("date_div").innerHTML = date_server;
                        }
                        function get_date() {
                                //put the return of php's show_now func
                                //to the javascript show_me func as a parameter
                                x_serverTime(show_me);

                                //do it every 1 second
                                setTimeout("get_date()", 1000);
                        }

Some advice would be great guys and even better an example if it will
be simple.

Thanks,
Angelos.

You can look at prototype.js with its auto updater

You can research COMET

FYI: if you expect a bunch of users on the system, these little requests may
= very big load on the box.

Eric

On 12/14/06, Aggelos <djje@gmail.com> wrote:

Ok cheers for that, I'll have a look now

-----------------------------------------------Reply-----------------------------------------------
OK i had a look on prototype but I cannot find an example that will do
what I want.
The problem is that all examples get triggered by something that the
user does...
I want the server somehow or an auto updater like you say to trigger
the php script :S

So I need that prototype autoupdater example ...

If someone has an example, please post it.

Thanks.

-----------------------------------------------Reply-----------------------------------------------

Just had it working using prototype and
<script>
new Ajax.PeriodicalUpdater("countSent", "test.php", {
 // initial number of seconds interval between calls
 frequency : 1,
 decay : 2
});

</script>

Thanks a lot Eric... it does exactly what I wanted in 3 lines of code
and the prototype library

The only bad thing is that I have to link to a url and not the function
directly though... Any ideas about that ?

Thanks again.

-----------------------------------------------Reply-----------------------------------------------

Well it would seem the sajax library that you originally used just did
an extra step of transforming a function in javascript to an ajax
request via a url to a function in php. That is, you call something
like update_time() in javascript and just get the result. But what
update_time() does in javascript is makes an ajax request to the sajax
hosting php file and calls the "get_time" function which it then
returns. Thus you're not really saving anything by trying to hide the
url thing. You may as well program as 80% of other people do and just
use a url. Feel free to wrap it in a function, although there's little
point.

And as Eric said, if you have more than a few users, updating every 1,
2, 3, 5, 10 seconds could soon put a lot of stress on your system. You
might consider something like comet (again as Eric said), where the
server actually sends new data to the client when and only when it is
available, rather than the client constantly polling the server,
although I'm unsure of how to implement this. I'm sure our good friend
Google knows, though.

Al

On Dec 14, 10:41 pm, "Aggelos" <djje@gmail.com> wrote:

hello Mr.alexrussell101

i'm a newbie in ajax and COMET, i want to learn about that,

where i can find a documentation about ajax and COMET..

thanx

-----------------------------------------------Reply-----------------------------------------------

hello

i'm a newbie in ajax and COMET, i want to learn about that,

where i can find a documentation about ajax and COMET..

thanx

-----------------------------------------------Reply-----------------------------------------------

On 15/12/06, jayz badboys <beagoodb@gmail.com> wrote:

> hello

> i'm a newbie in ajax and COMET, i want to learn about that,

> where i can find a documentation about ajax and COMET..

> thanx

I wanna know too !!!

-----------------------------------------------Reply-----------------------------------------------
Thanks for that. And what COMET does is exactly what I am looking.
Although I haven't heard of it.

I hope it is something I can learn fast though. The system at the
moment Will be used from a single user probably. But it will be used
from more in the near future...

SO I need to find some article which will explain how to implement it.

Thanks for pointing me in the right Direction Al ;)

-----------------------------------------------Reply-----------------------------------------------

> Thanks for pointing me in the right Direction Al ;)

That's okay, although Eric mentioned it first : )

> So I need to find some article which will explain how to implement it.

Well I don't use comet myself, so I don't know of any particularly good
articles, but I think I've read articles by the more famous Alex
Russell over at the dojo toolkit (http://www.dojotoolkit.org/) on the
matter. Maybe the dojo toolkit has some comet built in to it. If you
can't find anything there, Google always has plenty to say on most
topics. Sorry I can't really be any more help.

Al

-----------------------------------------------Reply-----------------------------------------------

No probs Al.
I thanked Eric as well I think.
If not. THanks Eric.

I'll google it ;)

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc