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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:03:13+00:00 2026-06-05T12:03:13+00:00

Hi guys i have the following code $.ajax({ url: http://localhost/twee/chat/getnumcom, type: ‘POST’, data: form_data,

  • 0

Hi guys i have the following code

$.ajax({
url: "http://localhost/twee/chat/getnumcom",
type: 'POST',
data: form_data,
success: function(html) {
            var data = parseInt(html);
                page = 20 * data ;

                while ( counter < page ) {

                       $.get("http://localhost/twee/chat/"+id+"/"+counter,function(data){
                       $('#c').append($(data).find('#c').html());
                       });      
                  counter = counter + 20 ;
               } 
          }
});

alert($('#600').length);
$.scrollTo('#600');

This is what it does. Originitally it appends data to my window until #600 is found. Technically i have a function which mathematically calculates where 600 should be. This is fine and the div is loaded nicely.

Howvever i added the alert specifically to check if the div is loaded. A value of 0 means no and a value of 1 means yes. In my firebug console, when the function is fired up, the while loop is still executing but the alert already displays a value of 0. Consequently, the scrolling is not done.

If i fire up the function again immediately after it has been executed, i get a 1 which means the div has been loaded.

Is there a way to delay the scroll function until the while loop has executed? I always thought the code would be executed procedurally and the alert would be displayed after all the data has been loaded.

I guess a timer would be an option but i don’t want to use that. I am not really sure how much milliseconds i should set the timer to.

  • 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-05T12:03:15+00:00Added an answer on June 5, 2026 at 12:03 pm

    Ajax calls are asynchronous, put your scrollTo/alert inside the success callback function, after the while loop:

    $.ajax({
        url: "http://localhost/twee/chat/getnumcom",
        type: 'POST',
        data: form_data,
        success: function (html) {
            var data = parseInt(html);
            page = 20 * data;
    
            while (counter < page) {
                $.get("http://localhost/twee/chat/" + id + "/" + counter, function (data) {
                    $('#c').append($(data).find('#c').html());
                    if ($('#600').length)   //if there's a #600 element inside this $.get callback
                        $.scrollTo('#600'); //scrolls to it
                });
                counter = counter + 20;
            }
        }
    });
    

    Note that numerical IDs are valid only in HTML5, if that’s of concern.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Guys, I have the following code that is inside a big while loop that
Guys i have used the following code to disable an option using jQuery (
guys, I have the following code, but I'm getting error at compiling time... the
.guys I have the following code: echo (<SCRIPT LANGUAGE='JavaScript'> window.alert('Succesfully Updated') </SCRIPT>); what i
guys i have seen following code in internet select round(abs(months_between(sysdate,add_months(hire_date,12*(round((months_between(sysdate,hire_date)/12))))))) from employees unfortunately there
Hi guys i have the following code which is part of the Twitter's bootstrap's
Hey guys I have the following code working which is sending a GET Request
Hey Guys I have the following simple Code : WhereAmIViewController.h #import <UIKit/UIKit.h> #import <CoreLocation/CoreLocation.h>
Hi guys i have the following code in my view: @model Test.tblReview @{ ViewBag.Title
Hi guys I have the following code and and I want it to last

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.