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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:31:25+00:00 2026-06-10T13:31:25+00:00

Possible Duplicate: jQuery: Return data after ajax call success jQuery AJAX: return value on

  • 0

Possible Duplicate:
jQuery: Return data after ajax call success
jQuery AJAX: return value on success

I can’t figure out why goodPassword always returns undefined
I”m sure it’s just a dumb mistake and will appreciate your answer

function foo(){
    var goodPassword;
    jQuery.ajax({
        data: "action=Potato",
        url: 'servletPotato',
        timeout: 2000,
        error: function() {
            console.log("Failed to send ajax");
        },
        success: function(r) {
            var data = jQuery.parseJSON(r);
            if(data.aprovePassword == "true")
            {
                goodPassword = true;
            }
            else
            {
                goodPassword = false;
            }
        }
    });
    return goodPassword;
}

the ajax call is definitely working and data.aprovePassword definitely return from the servlet as “false”

  • 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-10T13:31:27+00:00Added an answer on June 10, 2026 at 1:31 pm

    Because goodPassword hasn’t been assigned anything yet, since the XHR request executes after the function ends and that’s why by the end of the function, nothing has been assigned. An alternative function would be:

    function foo(successCallback) {
        var goodPassword;
         jQuery.ajax({
             data: "action=Potato",
             url: 'servletPotato',
             timeout: 2000,
             error: function() {
                console.log("Failed to send ajax");
             },
             success: function(r) {
                var data = jQuery.parseJSON(r);
                if(data.aprovePassword == "true")
                    {
                        goodPassword = true;
                    }
                else
                    {
                        goodPassword = false;
                    }
                successCallback(goodPassword);
           }});
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: jQuery: Return data after ajax call success I wrote a script which
Possible Duplicate: jQuery: Return data after ajax call success I have the following function
Possible Duplicate: Jquery: Return the value of a ajax call to caller function? In
Possible Duplicate: jQuery ajax return value I have this jQuery script: $('#headerSubmit').click(function() { var
Possible Duplicate: What does Asynchronous means in Ajax? jQuery ajax return value Trying to
Possible Duplicate: return AJAX callback return I have made a JQuery code using AJAX,
Possible Duplicate: jQuery Ajax always returns “undefined”? I'm trying to come up with a
Possible Duplicate: jQuery and AJAX response header If the server is returned data in
Possible Duplicate: jquery ajax call taking too long or something for some reason this
Possible Duplicate: JavaScript asynchronous return value / assignment with jQuery I need a prototype

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.