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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:52:47+00:00 2026-06-12T23:52:47+00:00

I have a question and I’m very surprised that I’ve never seen any script

  • 0

I have a question and I’m very surprised that I’ve never seen any script implementing such a technique, but I can’t solve it on my own, so I need a clue. To see what I want, please check out this basic page:

<!DOCTYPE html>

<html lang="en">

<head>

<style>

#loading{

display:none;

position: fixed;

width:500px;

height:200px;

top: 50%;

left: 50%;

margin-top: -100px;

margin-left: -250px;

z-index: 1;

border:black thin solid;

background-color: gold;}

</style>

<script src="path/to/jquery.min.js"></script>

<script>

        $(document).ready(function () {

        $('.click').click(function () {

        $("#content").empty();

        var src = $(this).attr('data-source').split(';');
        var l = src.length;
        $("#loading").ajaxStart(function(){
        $(this).html("Loading, please wait...").show();
        }).ajaxStop(function(){
        $(this).hide();
        });
        if (src.length >= 1 && src.length <= 5) {
            $.get(src[0].substring(src[0].lastIndexOf('@') + 1), {}, function (data) {
                var $response = $('<div />').html(data);
                $('#content').append($response.find(src[0].substring(0, src[0].lastIndexOf('@'))));
            }, 'html').complete(function () {
                $('#loading').html('Loaded: 1. Total: ' + l);
                if (src.length >= 2) {
                    $.get(src[1].substring(src[1].lastIndexOf('@') + 1), {}, function (data) {
                        var $response = $('<div />').html(data);
                        $('#content').append($response.find(src[1].substring(0, src[1].lastIndexOf('@'))));
                    }, 'html').complete(function () {
                        $('#loading').html('Loaded: 2. Total: ' + l);
                        if (src.length >= 3) {
                            $.get(src[2].substring(src[2].lastIndexOf('@') + 1), {}, function (data) {
                                var $response = $('<div />').html(data);
                                $('#content').append($response.find(src[2].substring(0, src[2].lastIndexOf('@'))));
                            }, 'html').complete(function () {
                                $('#loading').html('Loaded: 3. Total: ' + l);
                                if (src.length >= 4) {
                                    $.get(src[3].substring(src[3].lastIndexOf('@') + 1), {}, function (data) {
                                        var $response = $('<div />').html(data);
                                        $('#content').append($response.find(src[3].substring(0, src[3].lastIndexOf('@'))));
                                    }, 'html').complete(function () {
                                        $('#loading').html('Loaded: 4. Total: ' + l);
                                        if (src.length >= 5) {
                                                         $.get(src[4].substring(src[4].lastIndexOf('@') + 1), {}, function (data) {
                                                var $response = $('<div />').html(data);
                                           $('#content').append($response.find(src[4].substring(0, src[4].lastIndexOf('@'))));
        }, 'html').complete(function () {
        $('#loading').html('Loaded: 5. Total: ' + l);
        });
        }
        });
        }
        });
        }
        });
        }
        });
        } 
        });
        });
        </script>
</head>
<body>
<span data-source="#part1, #part3, #part4@page1.html;#part2@page2.html;#part5@page1.html" class="click">Click me</span>
<div id="content">
</div>
<div id="loading">Loading, please wait...</div>
</body>
</html>

That is, the elements are loading strictly in the order that I specified in my “data-source” attribute.
This script seems to work as I expect, but the problem is that I don’t want to “manually” write a separate function for every possible length!!! I want a script that will do this job automatically! I tried this:

   jQuery.each(src, function (i) {
            $.get(src[i].substring(src[i].lastIndexOf('@') + 1), {}, function (data) {
                var $response = $('<div />').html(data);
                var $ids = $response.find(src[i].substring(0, src[i].lastIndexOf('@')));
                $('#content').append($ids);
            }, 'html').complete(function () {
                $('#loading').html('Loaded: ' + (i + 1) + '. Total:' + l);
            });
        });

But in this case, due to the very nature of AJAX and the fact that jQuery.each is not equivalent to an infinite .complete(function () {… .complete(function () {… .complete(function () {… , the elements will not append in the same order that I specified, especially if they come from the same page. And if I write my data-source attribute as “page 1.html #part1, #part2” and use something like this:

    jQuery.each(src, function (i) {
            $('<div />').attr('class', 'container').appendTo($('#content')).load(src[i], function() {
    $('#loading').html('Loaded: ' + (i + 1) + '. Total:' + l);
    });
        });

The elements seem to append in a right order, and they do it the way I can’t understand: one just shifts down another, taking its place between the two already existing elements! But I can’t imagine where that HTML in my loading message comes from, it may just show that the pages are loading from last to first. I also tried to make use of ajaxComplete event and manipulate with the “data” attribute after my first Ajax call, but got no results.

So, is ajaxComplete equal to .complete(function () {… .complete(function () {… .complete(function () {… ? If it is, how can I tell to the script: “Start with the first element of this array, forget about the others. When you’re done, switch to the next… and so on, till the end”

  • 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-12T23:52:48+00:00Added an answer on June 12, 2026 at 11:52 pm

    I would suggest following solution with recursion:

    var i = 0; 
    var load = function (index) {
        $.get(src[index].substring(src[index].lastIndexOf('@') + 1), {}, function (data) {    
                var $response = $('<div />').html(data);    
                var $ids = $response.find(src[index].substring(0, src[index].lastIndexOf('@')));    
                $('#content').append($ids);    
            }, 'html').complete(function () {    
                $('#loading').html('Loaded: ' + (index + 1) + '. Total:' + l);
                              if(index +=1){
                    load(index += 1); //recursion
                              }
            });
    }
    load(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question that seems simple to you all but can't really get it.
I have question. I can do that every element of the ListView have a
I have question, maybe it's not critical in programming, but to me it's very
I have Question and QuestionTypes. In Question table there is a foreign key that
I have question i.e how can i select a previous div CODE:- if($i >
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question with this same title here but now as I'll present in
I have question about database optimizing, indexing. I have table that called projects and
i have question, i am using PHP script, there is something wrong when i
I have question about how I can save the result of function I have

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.