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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:48:13+00:00 2026-05-25T01:48:13+00:00

I’m trying to use the jQuery when function, in order to wait until an

  • 0

I’m trying to use the jQuery when function, in order to wait until an Ajax request completes before proceeding onwards, but am clearly getting something wrong.

My console output looks like this:

geocodeMaster
geocode Canary Wharf 
Object
geocode  
Object
address is blank, returning 51.501885 -0.190894
proceeding
Uncaught TypeError: Cannot read property '0' of undefined
Object
Object

The final two Objects are the output from the second call to geocode. Why does the code show proceeding before the output of the second call?

My code looks like this:

function geocode(address, geodata) {
    console.log('geocode', address, geodata);
    geodata['street'] = address;
    if (address=="") {
        console.log('address is blank, returning ' + current_latlng[0], current_latlng[1]);
        return [current_latlng[0], current_latlng[1]];  
    }
    $.ajax({
        url: CS_API + 'geocoder.json',
        data: geodata,
        dataType: 'jsonp',
        jsonpCallback: 'places',
        success: function(from_data) {
            console.log(from_data);
            if (from_data.results.result!=undefined){
               var from_result = from_data.results.result;
               console.log(from_result)
               return [from_result.latitude, from_result.longitude];   
            } else {
                return false;
            }
        },
        error: function(data) {
            return false;
        }   
    }); 
}
function geocodeMaster(place_from,place_to) {
    console.log('geocodeMaster');
    geodata['key'] = CS_API_KEY;
    if (current_latlng!=null) {
        geodata['n'] = current_latlng[0] + 0.1;
        geodata['e'] = current_latlng[1] + 0.1;
        geodata['s'] = current_latlng[0] - 0.1;
        geodata['w'] = current_latlng[1] - 0.1;
    }
    var start_coords,finish_coords;
    $.when(start_coords=geocode(place_from,geodata),finish_coords=geocode(place_to,geodata)).then(function(){
console.log('proceeding');
        console.log(start_coords[0],start_coords[1],finish_coords[0],finish_coords[1]);  
    });      
}

Is the problem that the objects supplied to when() are not Deferred objects? If so, how can I make them into Deferred objects, while keeping the information that I need to collect – start_lat, etc?

  • 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-25T01:48:14+00:00Added an answer on May 25, 2026 at 1:48 am

    You must return a deferred object from the geocode function. Try :

    return $.ajax(..
    

    You cannot store the return value directly into values (it does not work the way it’s written now). You have to store them somewhere else, so that the line that calls the when simply reads :

    $.when(geocode(place_from,geodata),geocode(....
    

    To solve this, you could pass to geocode an empty object, and have that function save its result in it, for example :

    var start_coords = {};
    var finish_coords = {};
    $.when(geocode(place_from,geodata,start_coords),geocode(place_to,geodata,finish_coords) ... 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.