Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Ronald Roe

Thread: ajax

  1. #1
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times

    ajax

    how can ajax be used to constantly check for new entries on a database then upload or notify a user when there is one, and then display, for the likes of an instant messenger or a live update news feed

  2.  

  3. #2
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times
    one other question, what is the need for an intitalisation function in javascript?

  4. #3
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    Quote Originally Posted by busso View Post
    how can ajax be used to constantly check for new entries on a database then upload or notify a user when there is one, and then display, for the likes of an instant messenger or a live update news feed
    It can't be used to constantly check. If you're going to use it like that, you'd have to run it on an interval. Really you would want to use Websockets for that, though: https://developer.mozilla.org/en-US/...WebSockets_API

    Quote Originally Posted by busso View Post
    one other question, what is the need for an intitalisation function in javascript?
    It keeps all of your variables and functions off the global scope by creating a closure around them. It makes for a safer environment for a few reasons: It keeps those items in the global scope from being overwritten by your code or creating other similar conflicts. It also keeps people from being able to open the console and run your functions.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."

  5. #4
    Senior Member
    Join Date
    Apr 2016
    Posts
    717
    Member #
    53891
    Liked
    11 times
    ahh clever js.

    I had suspected that a instant messenger feature on a website might be some sort of black magic like websockets, but would a status feed need the same black magic?

    I asked a similar question to a codecademy.com advisor and she told me that all an instant messenger is was messages being sent to a database and a notification sent to the users concerned, is that wrong?

  6. #5
    Senior Member Ronald Roe's Avatar
    Join Date
    Mar 2011
    Location
    Oklahoma City
    Posts
    3,141
    Member #
    27197
    Liked
    959 times
    My guess would be an interval-based request on the client side. So, every X milliseconds open an AJAX connection and check for new content. It would be easy enough to just send the last update's timestamp, then bump that against the update and send new information if available. Using Promises or jQuery's AJAX helper, you could even just create a recursive function that executes itself every time the connection completes, so you don't have overlapping requests.
    busso likes this.
    Ron Roe
    Web Developer
    "If every app were designed using the same design template, oh wait...Bootstrap."


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 06:16 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com