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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:54:59+00:00 2026-06-16T05:54:59+00:00

I find a fantastic bug when I use jQuery ajax to do a request

  • 0

I find a fantastic bug when I use jQuery ajax to do a request to web service:

var AjaxResult;
login = function () {
    AjaxResult = "";
    $.ajax({
        type: "POST",
        url: KnutBase.getServiceUrl() + "ServiceInterface/HmsPlannerWebService.asmx/AuthenticateLogin",
        data: { username: this.username, password: this.password },
        dataType: 'jsonp',
        success: function (response) {
            //the response value is 'success'
            AjaxResult = response;
        },
        error: function (data, status, e) {
            alert("error:" + e);
        }
    });

    //alert(AjaxResult);
    //if i do not alert a message here, this function will return a null value
    //however, i do alert here, then i get a 'success' value.

    return AjaxResult;
}

How could this happen.
I am confused as to why the AjaxResult returns its value before the ajax method set response value to 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-06-16T05:55:00+00:00Added an answer on June 16, 2026 at 5:55 am

    It has to do with the fact that AJAX is asynchronous (that’s actually the meaning of the first A in it). alert stops the code until you press the button, and the request has time to complete. With no alert, the function proceeds immediately, the AJAX has barely begun its work, and of course the value is still empty.

    Generally, you can’t have functions return values that they get from AJAX. Set up a callback for it, and deal with it when it comes.

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

Sidebar

Related Questions

find . -type f -print prints out ./file1 ./file2 ./file3 Any way to make
find . -type f | xargs file | grep text | cut -d':' -f1
I am using the rather fantastic jQuery multiple select plugin, ASM select This plugin
For some fantastic reason I find myself debugging a problem in a Classic ASP
I am using this fantastic example of a jQuery editable invoice as a template
I've been doing web development in Coda recently. It's a really fantastic app, however
ive searched around but couldnt really find anything to help. I use this code
Possible Duplicate: Use of var keyword in C# Hi, Just moved job and I
// Find smallest year int pastMin=0; int currentMin=ontarioBankInfoInt.get(0); int currentMinIndex=0; int reps=(ontarioBankInfoInt.size()-1)/3; for(int x=0;
find whether there is a loop in a linked list. Do you have other

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.