Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    PHP - Ajax Chat using logfile, without reload?

    Hello all,

    I have this PHP-jQuery-Ajax chat application, which uses PHP to open and write to a logfile and with jQuery and Ajax displaying and posting the messages.
    However, when loading the logfile with Ajax, there's a setInterval attached to reload it every 2.5 seconds or so.

    Now my problem is that when selecting content of the chatlog, the selection gets removed obviously, because of the reloading.

    How can I make the messages kind of permanent on the page, for selecting posted links and such.

    This must be possible some way, right, because chatmodules like Facebook's one also achieves this.

    Can someone please inform or instruct me on how to do this?

    Thanks!

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    Quote Originally Posted by fishbaitfood View Post
    Hello all,

    I have this PHP-jQuery-Ajax chat application, which uses PHP to open and write to a logfile and with jQuery and Ajax displaying and posting the messages.
    However, when loading the logfile with Ajax, there's a setInterval attached to reload it every 2.5 seconds or so.

    Now my problem is that when selecting content of the chatlog, the selection gets removed obviously, because of the reloading.

    How can I make the messages kind of permanent on the page, for selecting posted links and such.

    This must be possible some way, right, because chatmodules like Facebook's one also achieves this.

    Can someone please inform or instruct me on how to do this?

    Thanks!
    A link to your test page would do wonders for us.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. –G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,460
    Thanks
    11
    Thanked 600 Times in 580 Posts
    you can break the incoming data into chunks and render them atomically. this lets you always use append, which means you don't need to replace ui. If you mean a textarea, you'll have to manually memorize the .scrollTop, .selectionStart, and .selectionEnd properties, and re-set those to the old values after you change the .value.
    my site (updated 2014/10/20)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.3, IE11:9.2, IE9:2.7, IE10:2.6, FF:16.8, CH:47.5, SF:7.8, NON-MOUSE:37%

  • #4
    New Coder
    Join Date
    Nov 2011
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Solved it to only reload the content when a message is sent.
    But your append method, rnd me, is something to definately consider in the future! Thanks.
    And sorry Rowsdower!


  •  

    Posting Permissions

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