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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:49:51+00:00 2026-06-18T09:49:51+00:00

I am encountering a strange Javascript behavior: index.html <div id=content> <button type=button onclick=goDownload()>Click</button> </div>

  • 0

I am encountering a strange Javascript behavior:

index.html

<div id="content">
    <button type="button" onclick="goDownload()">Click</button>
</div>

hello.html

<div id="myId">
</div>

<script type="text/javascript">
    $(function() {
        doStuff();
    });
</script>

file.js

function goDownload() {
    $.ajax({
        url: "hello.html",
        cache: false,
        success: function (response) {
            $("#content").append(response);
        }
    });        
}

function doStuff() {
    //If I wait a little bit (e.g alert/timer), the below works
    //otherwise it does not

    $("#myId").html("Hello from doStuff()");
}

I know the ajax call is a async request, but I cannot see at what point this is becoming an issue. (I know I can do my doStuff() in success callback, but this is not the case for me). Any ideas?

  • 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-18T09:49:52+00:00Added an answer on June 18, 2026 at 9:49 am

    The result of an $.ajax call is a Deferred object ( http://api.jquery.com/category/deferred-object/ ), so you can take advantage of its methods to detect when it’s done:

    var downloadWaiting;
    
    function goDownload() {
        downloadWaiting = $.ajax({
            url: "hello.html",
            cache: false,
            success: function (response) {
                $("#content").append(response);
            }
        });
    }
    
    function doStuff() {
        downloadWaiting.done(function () {
            $("#myId").html("Hello from doStuff()");
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am seemingly encountering some strange behavior when using NSString 's -sizeWithFont family
I am encountering a strange javascript regex problem on Firefox 3.6 and Chrome 6
I've been encountering some strange behavior when trying to find a key inside a
Unexpected behavior: I am encountering strange behavior of Oracle sequences with 11g (works with
I am encountering strange behavior on my gnuplot script. The objective of this script
I am encountering some strange behavior with using the matplotlib.pyplot ginput() function to store
I'm encountering a strange behavior of MySQL. Query execution (i.e. the usage of indexes
I'm encountering a strange issue, where sqlsrv_query() returns a valid statement resource, but sqlsrv_fetch_array()
I am encountering a strange axis text alignment problem, as can be seen in
I am encountering a strange behaviour, my app runs smoothly on simulator but crashes

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.