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

  • Home
  • SEARCH
  • 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 6357905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:49+00:00 2026-05-24T23:15:49+00:00

I tried for several hours to get the following code working. The code should

  • 0

I tried for several hours to get the following code working.
The code should be paused until the page is loaded. The problem that I’m encountering is that the AJAX is executing asynchronously. How would I force the code to wait before executing?

var i = 1;
function On_Success(){

    i = i+1;
    if(i<=10){

    $('<div id="p'+i+'">b</div>').replaceAll('#b'); 
    $('#p'+i).load('tabelle.html');
    //here shoul be waited, til the page is loaded
    On_Success();
    };
    };

    function knopf(){
    $('body').append('<div id="p'+i+'">a</div>');
    $('#p'+i).load('tabelle.html'); 
    On_Success();
    };
  • 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-24T23:15:52+00:00Added an answer on May 24, 2026 at 11:15 pm

    .load accepts a callback that runs when loading is complete; you can use this instead of the more verbose jQuery.ajax function, which will require you to write additional code to populate your element.

    jQuery("#p", i).load("tabelle.html", function() {   
       //code to run when tabelle.html has finished loading
    });
    

    Change your code to the following. It should work:

    var i = 1;
    
    function On_Success() {
    
        i = i + 1;
        if (i <= 10) {
            $('<div id="p' + i + '">b</div>').replaceAll('#b');
            $('#p' + i).load('tabelle.html', On_Success);        
        };
    };
    
    function knopf() {
        $('body').append('<div id="p' + i + '">a</div>');
        $('#p' + i).load('tabelle.html', On_Success);
    };
    

    On another note, is it absolutely necessary that you should wait for one load to complete before populating the other divs? Why can’t you do something like this:

    function On_Success() {
        var i = 0;
        while(i < 11) {
            $('<div id="p' + i + '">b</div>').replaceAll('#b');
            $('#p' + i).load('tabelle.html');        
        };
    };
    

    Also, I’m not sure what the knopf function is doing. What should the value of i be in that function? How are you calling your code?

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

Sidebar

Related Questions

I've tried several of the solutions that I've found here, but none seem to
I really need advice on how to do the following. I have tried several
I've been struggling for several hours trying to figure out how to get this
I've been working on a solution to this for several hours now & figured
I've been hacking at a problem on and off for several days now that
I have spent the last several hours trying to get this to work and
I have spent several hours on this, and tried various things. I can confirm
ObjectContext instance has been disposed in InRequestScope! I tried for several hours across the
I've spent several hours over the past few days trying to get PostgreSQL to
I tried for several hours, to deliver my username and my password with query.

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.