Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default Ajax refresh/get.. help pls!

    Hi, I'm making a sort of chatbox kinda thing, and I've got it working so you enter your message, it posts it and you can see the last 5 messages. The thing is, to see new messages the page must be refreshed which is annoying, so I want it to automatically update the page with new posts/chats. Using META refresh works, but it's very noticeable on the browser (the loading icon starts moving).

    I want to do it with ajax. Problem is, I've never used ajax or javascript (much) so I need help. I've looked on Google, can't find what I want. All it needs to be is something that refreshes "get.php" every second, OR something similar that updates the page with a new post once its posted.

    If anybody could give me the code, either written by themselves or found off of Google I'd be so grateful!

    Thanks.

  2. #2
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Download this http://code.google.com/p/jqueryjs/do...query-1.3.2.js

    Then on your html page at the top (just below your title perhaps) put

    Code:
    <script src="pathtojqueryfile.js" type="text/js"></script>
    then make a file called core.js.

    Include the core.js just below the jqueryfile.js using the same code.

    core.js
    Code:
    function getLatest(){
                            
        $.ajax({
      url: 'PAGENAME.php',
      cache: false,
      success: function(data){
        $('#LATESTSHOUTSDIVIDGOESHERE').html(data);
      }
    });
            
        return false;    
    
    };
    Then I don't know how you are submitting the form but just do onclick="getLatest(); return false;" on the form as you post.

    You may want to add to that or perhaps just do the POST on it. I recommend reading the jQuery Documentation.

    Now in terms of getting the page to auto refresh every x seconds....

    Hmm. I guess you would just do a function like the one I said but call it onLoad and then put a setTimeout and restart the function and so on and so fourth.

    None of this is tested sorry.

  3. #3
    Join Date
    Dec 2006
    Location
    Swindon
    Posts
    3,299
    Tokens
    215
    Habbo
    dunko

    Latest Awards:

    Default

    Do the above but also edit it to check if the latest message given by the php doesn't equal the last message display, and if so insert the new shout (in a nice fashion or something) otherwise, don't.

  4. #4
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    Quote Originally Posted by Blob View Post
    Do the above but also edit it to check if the latest message given by the php doesn't equal the last message display, and if so insert the new shout (in a nice fashion or something) otherwise, don't.
    Yeh message ID definately. Good idea tbh.

  5. #5
    Join Date
    Jun 2006
    Posts
    4,832
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by BoyBetterKnow View Post
    Yeh message ID definately. Good idea tbh.
    Thanks both of you. I've found something that works - it was using some dudes javascript stuff and...

    new Ajax.PeriodicalUpdater('get', '/uge/get.php', {
    method: 'get', frequency: 0, decay: 0
    });

    Refreshes every second... might be a bandwidth waster, so I'll implement something in PHP where it checks if there are new ones as you said, cheers.

Posting Permissions

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