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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:44:50+00:00 2026-05-31T00:44:50+00:00

This question is maybe related to the question i asked here: Jquery ajax request

  • 0

This question is maybe related to the question i asked here: Jquery ajax request with async:true does not return value.

Now, i’m facing another problem. How do i retrieve the value from the callback function?

 function find_bus_route(array_bustops,callback){

            $.ajax({

            type: 'POST',
                async: true,
            url: 'find_routenum.php',

            data:{

                array_bustops:JSON.stringify(array_bustops)

            },
            dataType:'json', //html,xml

            success: function(my_results){

                callback(my_results);

            },

            error:function(x,e){
                if(x.status==0){
                alert('You are offline!!\n Please Check Your Network.');
                }else if(x.status==404){
                alert('Requested URL not found.');
                }
            }


        });

    }//end function

var arr_one;

    find_bus_route(arr_bus,function (data){
                                                                                 arr_one=data;
          alert(arr_one) //has correct value        

    }

alert (arr_one) //-->This returns undefined.. 

arr_one seems to be out of scope.

if(arr_one == arr_two){
   //do something.

}

actually what i’m trying to do is this:
assuming there is no callback and async is set to false and the function find_bus_route is returning a value.

var arr_one=find_bus_route(arr_stop1);
var arr_two=find_bus_route(arr_stop2);

if(arr_one==arr_two){
 //do something

}
else {
//do something


 };
  • 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-31T00:44:52+00:00Added an answer on May 31, 2026 at 12:44 am

    Since you call an external page aynchronously, you do not have the result immediately (depending on server/network load).

    In your code, the second alert (which displays undefined) is executed just after the AJAX call (response might not be obtained). The other one is executed when the JSON response is fetched. You can use return value only in success callback.

    I think you should explain us exactly what are you trying to do.

    EDIT :
    I think what you need is called deferred object, see this.
    With jQuery.when() you can wait for two asynchronous calls. The first example is exactly what you ask. In the when callback, you compare the two results.

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

Sidebar

Related Questions

maybe it's not so proper to ask this question here... anyway, I'm trying to
not sure if this question should be here or in serverfault, but it's java-related
This is related to the this question and the answer maybe the same but
Maybe this question has been asked many times before, but I never found a
This maybe a stupid question, but as I can not easily undo my change
This is closely related to anothewr question I have asked but since this is
This is related to this question I asked a while back. The end game
This is related to another question I recently asked about storing a non-bare repository
This question maybe a better fit on The Business of Software forum but despite
This question is for a web application. And maybe it's a stupid question but

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.