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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:29:25+00:00 2026-06-12T17:29:25+00:00

I have the following code: inside i put 2 alert() for debug. why does

  • 0

I have the following code:
inside i put 2 alert() for debug.
why does alert2 is shown before alert1 ???

<script language="javascript" type="text/javascript">
    $(document).ready(function () {

        $.ajax({
            type: "POST",
            url: "ManagerBaseKit.aspx/GetDummyVersions",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                var items = [];
                $.each(result.d.Version, function (key, val) {
                    items.push('<li id="' + key + '">' + val + '</li>');
                });
                $('<ol/>', {
                    'id': 'selectable',
                    html: items.join('')
                }).appendTo('.baseVersionsTest');
                alert('1'); // should be alerted 1st

            }
        });

        alert('2'); // should be alerted 2nd

    });

</script>

EDIT:
how can i make the $.ajax be called first thing?

  • 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-12T17:29:26+00:00Added an answer on June 12, 2026 at 5:29 pm

    Alert2 is triggered when the document is ready and Alert1 is triggered after a successful ajax request. You code could be re written in the form:

    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
         alert('2'); // Still the same functionality
    
            $.ajax({
                type: "POST",
                url: "ManagerBaseKit.aspx/GetDummyVersions",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    var items = [];
                    $.each(result.d.Version, function (key, val) {
                        items.push('<li id="' + key + '">' + val + '</li>');
                    });
                    $('<ol/>', {
                        'id': 'selectable',
                        html: items.join('')
                    }).appendTo('.baseVersionsTest');
                    alert('1'); // should be alerted 1st
    
                }
            });
    
    
    
        });
    
    </script>
    

    Now you can see why the Alert2 is triggered first (and on document ready)

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

Sidebar

Related Questions

I have the following JavaScript code which is inside a function which I am
When I'm trying to run the following code in IE:- <html> <head> <script language=javascript>
I have the following code inside a loop: Range(N & i + 1).Formula =
I have the following code with a bool if statement inside and in another
Inside my template function I have the following code: TypeName myFunction() { TypeName result;
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
I have the following code to create a LOG file. It is implemented inside
I have the following code inside my MainAcitivity for logging to the application using
I have the following code inside <table> tags. item is the result of the
I have the following code: <div id=parentDiv> <a href=someurl> ... </a> </div> HTML inside

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.