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 8711075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:47:07+00:00 2026-06-13T04:47:07+00:00

I need to use jQuery each function but also need it to work from

  • 0

I need to use jQuery each function but also need it to work from the first element to the last. Currently it seems to just be choosing random elements that match the criteria.

Here’s what I have:

$(".ago-time").each(function(index) {
    var old_ts = $(this).data("ts2");
    $.get("phpscripts/get_new_time.php", {
        old_ts: old_ts,
        index: index
    }, function(result) {});
    alert(result);
});

The index and old_ts are sent off to a php file where the output will be something like 0: 1 minute ago.

What I am getting in the alert is not in order (from 0 to highest). It will be something like this;

First alert:9: 10 mins ago

Second alert: 2: 4 mins ago

Third alert 5: 8 mins ago

As you can see the alerts are not in order of index so the each function must be selecting the ago-time‘s randomly.

  • 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-06-13T04:47:08+00:00Added an answer on June 13, 2026 at 4:47 am

    each does iterates sequentially over the matched elements over a jQuery object but the misunderstanding here is another.

    $.get is a shorthand $.ajax function, that’s an asynchronous HTTP request. The callback function, in this case:

    function(result) {
      alert(result);
    }
    

    is called asynchronously as you get the responses from the server.

    But, for what it seems, in your case this is irrelevant and a misunderstanding from you while trying to debug the server responses.

    For instance, in your code you can simply set the responses as you receive them from the server to their respective DOM elements.

    $(".ago-time").each(function(idx) {
      var $self = $(this);
      $.get("phpscripts/get_new_time.php", {
        old_ts: $self.data("ts2"),
        index: idx
      }, function(result) {
        $self.html(result);
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to use/reuse a external (normal) function into the jQuery.each(), like this: function
I need a way to use the jquery .live() function to act on elements
I need to use jquery to add and delete input fields based on user's
I have been using mootools for a year now. I need to use jquery
I use jquery picnet table filter - http://www.picnet.com.au/picnet-table-filter.html I need to display count of
I am need paint my image. I'm trying use JQuery in here this link:
I use a jquery validation plugin and I need to add some extra checking,
I'm stucking with jQuery where I need to use closest to get the .text()
Using ASP.NET MVC + jQuery : I need to use some values owned by
I need help to use jConfirm with this existing code (php & Jquery &

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.