-
Page Refresh
Is there anyway to refresh a page based on user input using php? or am i looking at javascript? Basically, i have a chatroom, and i don't want to use a meta tag because i want the page to refresh faster than every 5 or 1 seconds if it has to, or as slow as it has to, based on when any of the users sends a message. For example, 4 people are in my chatroom, one of them sends a message, and each of the 4 peoples page refreshes. Is that even possible using PHP or javascript?
Thanks.
P.S.: Sorry if this is in the wrong forum. I figured Javascript was strictly browser based and wouldn't be able to update each active user's page, and therefore i posted in here.
-
-
No. PHP is not realtime.
And, no. Javascript cannot access the server.
The ONLY way to do what you are asking is using AJAX.
More complex, but it's worth looking into.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
Oy, I was afraid of that. Hehe. I'm busy learning PHP, and all the while I'm learning more Javascript (it seems like to learn all of javascript would take an entire lifetime). I didn't want to have to get into AJAX too haha. Ah well, any idea where I can find a good AJAX tutorial to help me with this problem?
Thanks.
-
-
Not sure. I know WHAT AJAX can do, not so much HOW it does it 
It is all javascript based, though.
You send a request for a page, using javascript. That is "AJAX".
Then you'd control that process using javascript, ifs, loops, user input, whatever.
Not TOO complex... but certainly advanced.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
The server cannot initiate a connection to the client. The client must send a request before any data can be sent by the server. This means that you have no way of telling when there is a new message available. You simply have to refresh periodically. Through trial and error with people of different connection speeds, I find five seconds is probably the best interval.
-
-
The only catch is that using AJAX, you can "refresh" every 5 seconds, but only actually refresh the text if it varies from what it was before.
That's a very nice trick, and looks a lot better than flashing text.
But, exactly... the server can't initiate anything. That's the hard part about coding chatrooms, etc.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
Hm. So I'm probably better off just using a meta tag?
-
-
You're better off using XMLHttpRequest, then falling back on a meta tag. Check out the PHP/MySQL chat I wrote for Johnnymushio. I hope he won't mind my using it as an example, I've just moved to a new host and I don't have everything up yet.
-
-
Twey, would you consider releasing that? I'd certainly love a copy
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
-
What is XMLHttpRequest? I went to that link you gave me, but I don't know exactly what i'm looking for there.
Is this XML thing the best answer to my problem?
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks