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

The Archive Base Latest Questions

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

With async:set to false, the function is returning the correct value. However it blocks

  • 0

With async:set to false, the function is returning the correct value. However it blocks the browser. I’ve tried to add callbacks but it not returning the correct value!

function find_route(array_bustops){
        var myresults;
            $.ajax({

            type: 'POST',
                async: true,  //with async:false it works
            url: 'find_routenum.php',

            data:{

                array_bustops:JSON.stringify(array_bustops)

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

            success: function(my_results){

                myresults=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.');

            }


        });

        return myresults;
    }

WITH CALLBACK:

function find_route(array_bustops,callback){
        var myresults;
            $.ajax({

            type: 'POST',
                async: true,  //with async:false it works
            url: 'find_routenum.php',

            data:{

                array_bustops:JSON.stringify(array_bustops)

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

            success: function(my_results){

                callback(array_bustops,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.');

            }


        });

        return myresults;
    }
    function find_route2(myresults){
           return myresults;
    }

And then i call the function as follows:

arr_one=find_route(arr,find_route2)

but arr_one returns undefined.

EDIT: it still is not working with async:set to true

  • 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:48:28+00:00Added an answer on May 31, 2026 at 12:48 am

    arr_one=find_route(arr,find_route2)

    this got nothing to do with async but with the architecture of your code.

    you declare myresults in the scope of find_route, when you call find_route the function return the value of myresults who is undefined because you delcare it only.

    Try to declare var myresults=’somevalue’; in your function

    Now your function return ‘somevalue’

    This happen because the call to ajax method will not stop the function execution and the success method will be executed way after find_route is called and returned just put a console.log in there you’ll see that it will get log eventually when the success is called.

    It work when async false is set because async false as you discover stop the function execution from returning before the ajax call is back

    Edit: possible solution

    function DataListener(val){
        this.val = val;
        this.remoteFetch();
    }
    
    DataListener.prototype.set = function(val){
        this.val = val;
        this.notifyListener(val)
    }
    DataListener.prototype.get = function(val){
        return this.val;
    }
    
    DataListener.prototype.remoteFetch = function(){
        $.ajax({
            success:$.proxy(this, 'set')
        })
    }
    
    var arr_one = new DataListener('somevalue');
    alert(arr_one.get());// alert somevalue
    
    function doSomething(arr_one_value){
        alert(arr_one_value); // the new value set from the ajax call   
    }
    
    arr_one.addListener(doSomething);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The jQuery docs strongly urge you not to set async to false when performing
I'm running into an issue with a jquery ajax function not properly returning its
In jQuery there's an option to set AJAX calls to be synchronous: async: false
I have this function: public static void Play(string FileName, bool Async = false) {
Why the return value of my function always false this is my function: function
For example function getResult(field) { $.ajaxSetup ({cache: false, async: false}); $.get(api.php?field=+field, function(i) { result
Set objNoFormCheckXMLDOM = CreateObject(Microsoft.XMLDOM) objNoFormCheckXMLDOM.async = false objNoFormCheckXMLDOM.setProperty SelectionLanguage, XPath objNoFormCheckXMLDOM.LoadXML(strHtmlResponse) Set nlForms =
Suppose you want to make an async request in JavaScript, but you want to
I want the check_membership() function below to return the AJAX data. However, result keeps
I have an async call that, when it completes, I want to set a

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.