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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:24:13+00:00 2026-05-30T22:24:13+00:00

I have the strangest Bug, my Javascript function behaves differently depending on wether or

  • 0

I have the strangest Bug, my Javascript function behaves differently depending on wether or not an alert is set on a specific Line.

Basically the Code looks like this:

var friendsHtml = 'Error String';
$.get("url", function(xml){
    $(xml).find('friend').each(function(){
        friendsHtml = 'html stuff';
    });
});
var div = '<div>'+friendsHtml+'</div>';
$("#friends_window").html(div);

Which will always display the Error String and not the HTML String.
But when i add an empty alert on this line, everything works just fine:

var friendsHtml = 'Error String';
$.get("url", function(xml){
    $(xml).find('friend').each(function(){
        friendsHtml = 'html stuff';
    });
});
alert("");
var div = '<div>'+friendsHtml+'</div>';
$("#friends_window").html(div);

I really don’t get it.

  • 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-30T22:24:14+00:00Added an answer on May 30, 2026 at 10:24 pm

    The alert blocks (“pauses”) the execution of the function, but not the AJAX request.

    So, when you hit “OK” to dismiss the alert dialog, the request may have finished, and the friendsHtml variable is then changed by the callback method in jQuery.get.

    A visualisation:

    // Case 1
    var friendsHtml = 'Error String';
    < sending AJAX request... >
    var div = '<div>'+friendsHtml+'</div>';  // <AJAX request hasn't finished yet
                                             // so "Error String" is printed.
    // Case 2:
    ...
    < sending AJAX request >
    alert("");                           // <-- Blocks execution
                                         // Meanwhile, AJAX request finishes
                                         // and changes friendsHtml to "html stuff"
    < User dismisses dialog, and the execution is resumed >
    var div = '<div>'+friendsHtml+'</div>'; // <-- "html stuff"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have encountered a very strange bug in Firefox. I have a javascript function
I could reproduce my bug using servside OAuth2.0 only so it's not javascript and
i have the strangest bug. in my php file i include several php files:
I've come across the strangest bug pertaining to DataGridViews in Windows Forms. I have
I have datagrid and noticed strange bug: I set HeadersVisibility=All. And when move mouse
I have a strange bug with bookmark counts - if I set/inc. the bookmark
I have a strange bug. I launch a PHP Unit test Suite. At the
I have a very strange bug, which I believe is caused by some code
I have a really strange enum bug in Java. for(Answer ans : assessmentResult.getAnswersAsList()) {
I have come across some strange behaviour, and I'm assuming a bug in Firefox,

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.