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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:57:32+00:00 2026-06-06T12:57:32+00:00

i have problem.. for(a=1;a<10;a++){ $(.div).append(<div id=+a+></div>) $.ajax({ url: file.php, data: a=+a, type: POST, async:

  • 0

i have problem..

for(a=1;a<10;a++){
    $(".div").append("<div id="+a+"></div>")
        $.ajax({
              url: "file.php",
              data: "a="+a,
              type: "POST",
              async: false,
              success: function(data) {
                $("#"+a).html(data);
              }
        });

}
 $("div").click(function(){
        alert("it works");
 });

problem is:
is I didn’t put there async: false data from file.php are only in last div so with id 9
but now there is async: false – so data are in every div so that is good

but if i want click while it was loading by ajax it doesn’t work (only after finished all ajax-es)

how resolve this problem? (maybe the false is that am I using ajax. I can use getJSON ect..)

thanks for helping

  • 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-06T12:57:34+00:00Added an answer on June 6, 2026 at 12:57 pm

    If you want the user to be able to use the interface while the ajax call is running, you should change your async to true. It has also been noted by James Allardice that in this scenario you need to use a javascript closure to retain the value of your original id for when the ajax call is returned. For more information regarding javascript closures check out how-do-javascript-closures-work, a really good question found here on stackoverflow.

    for(id = 1; id < 10; id++){
        $(".div").append("<div id='" + id + "'></div>");
    
        (function(id) {
            $.ajax({
                url: "file.php",
                data: "a=" + id,
                type: "POST",
                async: true,
                success: function(data) {
                    $("#"+ id).html(data);
                }
            });
         }(id));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

have a problem. At first look at this HTML <div id=map style=background-image: url(map.png); width:
I have populated an asynchronous ajax function which grabs data from an xml: $.ajax({
I have the following fom: form id=login_form class=fancy_form action=@Url.Action(Logon, Account) method=POST> <div class=bl_label> Eneter
I have a little problem with my click event. I have an AJAX function
I have a problem about div position relative alignment. I want the second div
Hi all I have problem with my div's in html. I have set them
i have problem with image vertical-align in div .img_thumb { float: left; height: 120px;
I have a div with <img> and <a> in it. But I have problem
I have a problem to load specific div element and show on my page
I have a problem with position of a block (div). I am newbie in

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.