Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7218463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:29:08+00:00 2026-05-28T21:29:08+00:00

Here’s what I’m trying to do. I’m trying to pull data from a database

  • 0

Here’s what I’m trying to do. I’m trying to pull data from a database and create a new user and continue to check every second for new users and changes in previous users’ location (I’m tracking GPS using an Android app). I need to be able to create a new instance each time a new user is added to the DB, but I’m not sure how to do this. I’ve seen examples like below, but the objects are defined within the program and aren’t created ‘automatically.’

function cat(name) {
this.name = name;
this.talk = function() {
    alert( this.name + " say meeow!" )
    }
} 

cat1 = new cat("felix")
cat1.talk() //alerts "felix says meeow!"

cat2 = new cat("ginger")
cat2.talk() //alerts "ginger says meeow!"

Let’s say I wanted to pull the cat’s name from a database and check for new ones each second. I would have a php program that pulls and returns it to this JS program as JSON, but how do I instantiate a new ‘cat’ by using a function? Any help would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T21:29:09+00:00Added an answer on May 28, 2026 at 9:29 pm

    I’m not going to overcomplicate this with long-polling or anything – for the sake of getting you started I’ll just assume you can use setTimeout() to check for new users every thirty seconds or something. Sticking with your existing cats() constructor you could do something like this:

    var cats = [];
    
    function checkForNewCats() {
       $.ajax({
          url: "getcats.php",
          data : { lastCat : (cats.length == 0 ? "" : cats[cats.length-1].name) }
       })
       .done(function(data) {
          $.each(data, function(i, val) {
             cats.push(new cat(val.name));
          });
       })
       .fail(function() {
          alert("Something went horribly wrong");
       })
       .always(function() {
          setTimeout(checkForNewCats, 30000);
       });   
    }
    
    checkForNewCats();
    

    So that includes an array cats to hold all the objects, and then a function that repeatedly makes an ajax request a couple of times a minute to check for new cats and add them to the array.

    This assumes that the JSON returned by the PHP is an array of cat objects something like:

    [
      { "name" : "fluffy" },
      { "name" : "sneezy" },
      { "name" : "ned" }
    ]
    

    Where obviously you can add extra properties for each cat. Presumably your real world application would have some sort of user id, a name, and the GPS location(s) you mentioned.

    The data attribute that I set for the ajax request:

    data : { lastCat : (cats.length == 0 ? "" : cats[cats.length-1].name) }
    

    Is basically passing through the name of the last cat and leaving it to the PHP to then return only the names of cats added since that one. Obviously in a real world app you would use a user id or record timestamp for that purpose.

    EDIT: Old syntax for jQuery Ajax –

    function checkForNewCats() {
       $.ajax({
          url: "getcats.php",
          data : { lastCat : (cats.length == 0 ? "" : cats[cats.length-1].name) },
          success : function(data) {
             $.each(data, function(i, val) {
                cats.push(new cat(val.name));
             });
             setTimeout(checkForNewCats, 30000);
          }
       });   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the flow that I am trying to achieve: 1) User uploads an audio
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Basically, what I'm trying to create is a page of div tags, each has
Here's my procedure: DROP PROCEDURE IF EXISTS `couponExpires`$$ CREATE DEFINER=`root`@`localhost` PROCEDURE `couponExpires`(IN couponID BIGINT,
Here is my problem : I have a post controller with the action create.
Here is an example. foreach (var doc in documents) { var processor = this.factory.Create();
Here's what I'm trying to accomplish with this program: a recursive method that checks
Here is the css: #content ul { font-size: 12px; } I am trying this:
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.