Page 1 of 3 123 LastLast
Results 1 to 10 of 21

Thread: Page Refresh

  1. #1
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

  3. #3
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

  7. #7
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hm. So I'm probably better off just using a meta tag?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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 | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

  10. #10
    Join Date
    Feb 2006
    Posts
    158
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •